Draft PEP: string interpolation with backquotes
Greg Ewing
greg at cosc.canterbury.ac.nz
Mon Dec 3 00:38:45 EST 2001
Fernando Pérez wrote:
>
> phil hunt wrote:
>
> >>
> >> "x is $x, f(x) is $f(x)"
> >>
> >>This to me is readable, unambiguous and very useful.
> >
> > To me it implies the same as:
> >
> > "x is %(x)s, f(x) is %(f)s(x)" % { 'x': x, 'f': f}
> >
> No. $_whatever_ means: fully evaluate _whatever_, as far as it can be
> evaluated,
Um, in that case,
"x is $x, f(x) is $f(x)"
would mean the same as
"x is %s is %s" % ((x, f(x)), f(x))
which I don't think is quite what was intended.
Also, what is the parser supposed to make of things like
$"x is $x & y is $y"
? Is it supposed to be smart enough to realise that it
has to stop after "x" and not try to interpret the rest
as an '&' operator followed by a variable followed by
an 'is' operator followed by a syntax error?
I think that "as far as it can be evaluated" is too
fuzzy a specification. Even if the parser can be taught
to understand exactly what it means, I'm not sure that
humans can...
--
Greg Ewing, Computer Science Dept, University of Canterbury,
Christchurch, New Zealand
To get my email address, please visit my web page:
http://www.cosc.canterbury.ac.nz/~greg
More information about the Python-list
mailing list