string interpolation (Was: Newbie can't figure out documentation practices)

Erik Max Francis max at alcyone.com
Mon May 12 05:41:57 EDT 2003


Antonios Christofides wrote:

> You could have been in my mind. My second thread to this group would
> be
> that the only thing I'm missing badly from Perl is string
> interpolation.

I don't know, it doesn't seem all that awful to me in Python:

>>> name = "John"
>>> age = 23
>>> "The age of %(name)s is %(age)d." % locals()
'The age of John is 23.'

More featureful than Perl string interpolation, in fact, since it can do
full printf-like handling:

>>> '%(x)04d' % {'x': 1}
'0001'

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ It seems like Karma's making his rounds
\__/ Kina
    Church / http://www.alcyone.com/pyos/church/
 A lambda calculus explorer in Python.




More information about the Python-list mailing list