[Python-Dev] Can we please have a better dict interpolation syntax?

Guido van Rossum guido at python.org
Thu Oct 23 00:16:19 EDT 2003

> > Wouldn't this be even better?
> > 
> >     "create index ${table}_lid1_idx on $table($lid1)" % params
> I wouldn't object to that. I'd have expected *you* to
> object to it, though, since it re-defines the meaning
> of "$" in an interpolated string. I was just trying
> to suggest something that would be backward-compatible.

Correct, my proposal can't be backward-compatible. :-(

But somehow I think that, for various cultural reasons (not just Perl
:-) $ is a better character to use for interpolation than % -- this is
pretty arbitrary, but it seems that $foo is just much more common than
%foo as a substitution indicator, across various languages.  (% is
more common for C-style format strings of course.)

There have been many proposals in this area, even a PEP (PEP 215,
which I don't like that much, despite its use of $).

Many people have also implemented something along these lines, using a
function to request interpolation (or using template files etc.), and
using various things (from dicts to namespaces) as the source for

Anyway, I think this is something that can wait until 3.0, and I'd
rather not have too many discussions here at once, so I'd rather
unhelpfully punt than take this on for real (also for the benefit of
Brett, who has to sort through all of this for his python-dev

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list