Whatever happened to String Interpolation?

Kragen Sitaker kragen at pobox.com
Sat Dec 1 18:40:51 EST 2001


Skip Montanaro <skip at pobox.com> writes:
> (or something else similar) which isn't all that readable either.  You just
> happen to want to embed literal %-signs in your strings.  Please correct me
> if I'm wrong, but changing the character that introduces a value to be
> interpolated just moves the problem around a bit.  I don't think it solves
> anything.

Ping's PEP has some advantages over %-syntax; in the common case of
interpolating a variable, you need only type $var, rather than
%(var)s, and in the less-common case of wanting to interpolate an
expression evaluated in the current namespace, you can do that too,
still with one less noise character than the % syntax allows.  (I have
a module that lets you evaluate arbitrary expressions with the %
syntax, and I've heard other people have written them too.)

In short, if %s and $s are equally frequently desired literal
characters, the syntax is less noisy, which I think is important,
given the importance of the task.  I don't have any idea which one is
more common, myself.




More information about the Python-list mailing list