What is this syntax ?

Vito 'ZeD' De Tullio zak.mc.kraken at libero.it
Mon Jun 20 01:42:45 EDT 2011


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




More information about the Python-list mailing list