[Python-Dev] extended print statement, uPre-PEP

Paul Prescod paul@prescod.net
Mon, 24 Jul 2000 02:23:30 -0500


"Barry A. Warsaw" wrote:
> 
> ...
> The nugget of interesting new
> functionality here is that your doing attribute lookup inside a string
> interpolation, and /that/ might be a cool thing to have.  

Attribute lookup is just a special case of expressions. What if I needed
to do a function call?

*You* were the one that prompted me to think up this syntax (actually I
probably remembered some it from some work Ping did years ago...)

The original example had a function call in it. There is no nice way to
integrate a function call (or method call) into ""%vars(). That's what
gave rise this this:

 print >> log, 'post to %(listname)s from %(sender)s, size=%(msglen)s' %
{
       'listname': listname,
       'sender'  : sender,
       'msglen'  : len(msg),
       }

It seems we're going around in circles, though. You were the one that
said that the percent operator is inconvenient way back here:

http://www.python.org/pipermail/python-dev/2000-July/013837.html

I think you were right back then!

Also, I agree with Tim that what we have is great for all kinds of
corner cases but a pain for a lot of the common ones.

Other minor problems include: 

 1. "Why do I have to say the s in %()s when I'm using the s formatting
code 97.68% of the time?" I shouldn't need to. To me, the s looks like a
pluralization of listname and sender. A template should have clear
delimiters so that it is straightforward to read.

 2. "Why do I have to tell it what namespace to evaluate in when 93.5%
of the time, it's vars()?"

Anyhow, you may be right that a less severe change is possible. I went
with the dollar sign syntax because a) it is very much like many other
languages that many programmers have used and b) because it didn't have
the backwards compatibility issues of trying to stay compatible with
printf (especially that trailing-s thing).


-- 
 Paul Prescod - Not encumbered by corporate consensus
New from Computer Associates: "Software that can 'think', sold by 
marketers who choose not to."