Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #7999

Re: What is this syntax ?

From Vito 'ZeD' De Tullio <zak.mc.kraken@libero.it>
Subject Re: What is this syntax ?
Followup-To gmane.comp.python.general
Date 2011-06-20 07:42 +0200
References (2 earlier) <roy-2A6DC8.11394419062011@news.panix.com> <e724fc3e-8198-4fb7-b1d3-96834f3fa6bb@34g2000pru.googlegroups.com> <roy-DD0C35.16204819062011@news.panix.com> <mailman.164.1308517611.1164.python-list@python.org> <4dfe841c$0$30002$c3e8da3$5496439d@news.astraweb.com>
Newsgroups comp.lang.python
Message-ID <mailman.169.1308548598.1164.python-list@python.org> (permalink)

Followups directed to: gmane.comp.python.general

Show all headers | View raw


Steven D'Aprano wrote:

>> and you can achieve php interpolation via locals()
>> 
>>>>> a = 'b'
>>>>> print("%(a)s" % locals())
>> b
> 
> You can do that, but when reading code I consider any direct use of
> locals() (and globals() for that matter) to be a code smell:

well you're right, me neither like very much to touch locals() and (worse) 
globals(), but

1) this is the "php interpolation" Roy Smith asked for: 
       print "$scheme://$host:$port/$route#$fragment"
   where are defined scheme, host, port, route and fragment?
   or you think also this is "code smell"?

2) I'm in no way modifying the dict, just accessing in read only.

3) I'm restricting to locals() :D


btw I never used dict to format strings, so I learned how old this feature 
is :D

-- 
By ZeD

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

What is this syntax ? candide <candide@free.invalid> - 2011-06-19 15:41 +0200
  Re: What is this syntax ? Laurent Claessens <moky.math@gmail.com> - 2011-06-19 15:50 +0200
  Re: What is this syntax ? Noah Hall <enalicho@gmail.com> - 2011-06-19 14:58 +0100
  Re: What is this syntax ? Chris Angelico <rosuav@gmail.com> - 2011-06-20 00:03 +1000
  Re: What is this syntax ? candide <candide@free.invalid> - 2011-06-19 17:08 +0200
    Re: What is this syntax ? Roy Smith <roy@panix.com> - 2011-06-19 11:39 -0400
      Re: What is this syntax ? rusi <rustompmody@gmail.com> - 2011-06-19 09:58 -0700
        Re: What is this syntax ? Roy Smith <roy@panix.com> - 2011-06-19 16:20 -0400
          Re: What is this syntax ? Vito 'ZeD' De Tullio <zak.mc.kraken@libero.it> - 2011-06-19 23:06 +0200
            Re: What is this syntax ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-19 23:19 +0000
              Re: What is this syntax ? Vito 'ZeD' De Tullio <zak.mc.kraken@libero.it> - 2011-06-20 07:42 +0200
          Re: What is this syntax ? Benjamin Kaplan <benjamin.kaplan@case.edu> - 2011-06-19 15:29 -0700

csiph-web