Variable Interpolation - status of PEP 215
Ganesan R
rganesan at myrealbox.com
Thu Jun 20 00:34:52 EDT 2002
>>>>> "Peter" == Peter Hansen <peter at engcorp.com> writes:
> Evading the question: are you aware of the ability of the Python
> formatting operator to retrieve items from a dictionary rather
> than just by order in a sequence?
I remember reading about this ..
>>>> foo = "trick"
>>>> bar = 95.5
>>>> print "This %(foo)s is loved by %(bar)s%% of programmers." % locals()
> This trick is loved by 95.5% of programmers.
> You can use any dictionary, but locals() or globals() can be handy
> in many cases.
but didn't know this particular trick. Pretty cool! Thanks. At least I am
glad that Python has the % formatting operator. I have to program in Java at
work and don't even ask me about the pain of printing messages in that
language :-(. And yes, I do know about Jython and love it :-).
Ganesan
--
Ganesan R
More information about the Python-list
mailing list