string interpolation syntactic sugar
hartmut Goebel
hartmut at oberon.noris.de
Sat Dec 11 17:31:39 EST 1999
Skip Montanaro (skip at mojam.com) schrieb:
>Referring to
>
> "a %(x)s b %(y)s" % locals()
>and
> "a %(x)s b %(y)s" % obj.__dict__
>
>Hartmut asks:
>
> How efficient is this?
>
>Efficient enough. ;-)
Oh, I should have been more verbose:
Beening brand new to Python, I may miss some information yet :-) But I
suppose, local() generates a new tuple. This may be quite unefficient.
>You have to count format
>elements from the beginning of the format string to the point at which you
>want the new % thingie, then do the same in the tuple of substitution
>values. An error-prone exercise, to be sure, especially if the values are
>more complex (function calls with multiple arguments, yadda, yadda, yadda).
Sure, that's why I'm pretty happy to have this "interpolate" feature right
now :-)
>Skip Montanaro | http://www.mojam.com/
+++hartmut
More information about the Python-list
mailing list