[Python-Dev] PEP 215 redux: toward a simplified consensus?
Mon, 25 Feb 2002 12:31:55 -0800
"Barry A. Warsaw" wrote:
> >>>>> "MAL" == M <firstname.lastname@example.org> writes:
> MAL> 'Joe has $$ $a in his pocket.' $ locals()
> I'd prefer to hijack an existing operator -- one that's unsupported by
> the string object. Perhaps / or - or & or |
String interopolation should be a *compile time* action, not an
operator. One of the goals, in my mind, is to allow people to string
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).
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.
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.
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