Draft PEP: string interpolation with backquotes

phil hunt philh at comuno.freeserve.co.uk
Mon Dec 3 13:24:46 EST 2001


On Sun, 02 Dec 2001 20:30:34 +2328, Fernando Pérez <fperez528 at yahoo.com> 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.

Wrong. Read what I said closely. I am right on this, beleive me.

> $_whatever_ means: fully evaluate _whatever_, as far as it can be 
>evaluated, and put its value in there. So it gives an interpolation 
>syntax which is in fact much cleaner than perl's, with much less need 
>for braces and name protection.

If you want Perl-like features, you can always use Perl.

>> 
>> What's wrong with the existing way of doing things with "%"?
>> 
>
>Try using the  existing syntax for really complex cases.

Easy:

   "some %s expression" % really_complex_expression()

What's wrong with that?

Anyway, having complex espressions interleaved with static text, whether
you do it the Perl way or the C++ way, makes the code less readable, IMO.


> In the post 
>you quote, I explicitly showed what the current options are, and 
>their flaws. For one-liners it doesn't matter. The problem is 
>*scalability*. As always, easy problems can be solved easily. The 
>question is: is the tool good enough for solving the hard problems? 
>If you read my complete post, either you'll agree that it doesn't or 
>you'll give me a counter argument. But read and argue on the whole 
>post, not just a snippet of it.

I've re-read your whole post, and still don't see any problem. You mention
long strings with lots of lines and lots of values to fill in. I've done
that with the % oprator, with no problems. I disagree that using a temporary
variable here is a problem, to me it doesn't reduce clarity at all.

I would have no problem with someone intruducing i"....$x...." as a
preprocessor to Python(*), but I do not think it should go in the language.


[*] I have done something similar with having HTML statements which are
converted to strings with %(variable)s inside them and replaced by Python
at run time. If you have a specialised use like that, then it is sensible 
to write a Python progrsam to solve your problem. But the Python language
and syntax is good as it is, and doesn't need any extra complexity.


-- 
*** Philip Hunt *** philh at comuno.freeserve.co.uk ***



More information about the Python-list mailing list