[Python-Dev] PEP 215 redux: toward a simplified consensus?

Fred L. Drake, Jr. fdrake@acm.org
Mon, 25 Feb 2002 15:55:15 -0500

Paul Prescod writes:
 > String interopolation should be a *compile time* action, not an
 > operator. One of the goals, in my mind, is to allow people to string

This doesn't work as soon as the string is not a constant.  Many of
the discussions at PythonLabs did not involve text included as part of
an application's source, and the conversion operation would not be
driven by application code but by library/service code.  Even if it
were a constant, needing to add in message catalog support changes
things as well.  So auto-magical interpolation doesn't seem like a
good idea.

 > interpolate without knowing what the locals() function does. After all,
 > that function is otherwise useless for most Python programmers (and
 > should probably be moved to an introspection module). 

You'd still only need to use locals() if that's your source of

 > Your strategy requires the naive user to learn a) the $ syntax, b) the
 > magic operator syntax and c) the meaning of the locals() function. Plus
 > you've thrown away the idea that interpolation works as it does in the
 > shell or in Perl/Awk/Ruby etc.

a) The $ syntax is easier than the % syntax, and already more familiar
   to most new users.
b) What's a magic operator?  string % mapping is already pretty
   magical as far as the modulus operation is concerned.
c) And you still don't have to use locals() if you don't want to.

And the string syntax matches a common subset of what's used
elsewhere.  We just have the added control over the source of
substitution values (a good thing).

 > At that point, in my mind, we're back where we started and should just
 > use %. Well have reinvented it with a few small tweaks.

And we've made it a lot easier for strings that are not part of Python
source code, and for people who produce that data but never know

 > Plus, operator-based evaluation has some security implications that
 > compile time evaluation does not. In particular, if the left-hand thing
 > can be any string then you have the potential of accidentally allowing
 > the user to supply a string that allows him/her to introspect your local
 > variables. That can't happen if the interpolation is done at compile
 > time.

I'm not sure I understand this.


Fred L. Drake, Jr.  <fdrake at acm.org>
PythonLabs at Zope Corporation