Whatever happened to String Interpolation?

Skip Montanaro skip at pobox.com
Fri Nov 30 00:23:23 CET 2001

    fp> I'm a big fan of Ka-Ping Yee's Itpl module (which allows strings of
    fp> the form 'the value of x is $x', but I often find myself not using
    fp> it so as not to add an extra dependency to a program I want to keep
    fp> small.

I know it's a little more verbose, but what's wrong with

    'the value of x is %(x)s' % locals()

(or something similar?  As has been demonstrated recently on the list, you
can easily create a dict-like object that allows you to interpolate complex
expressions as well.

Skip Montanaro (skip at pobox.com - http://www.mojam.com/)

More information about the Python-list mailing list