[Python-Dev] *Simpler* string substitutions

Christian Tismer tismer@tismer.com
Fri, 21 Jun 2002 13:09:33 +0200


M.-A. Lemburg wrote:
> Alex Martelli wrote:
> 
>> If %(name)s is to be deprecated moving towards Python-3000 (surely it
>> can't be _removed_ before then), $-formatting needs a very rich 
>> feature set; otherwise it can't _replace_ %-formatting.  It seems to 
>> me that (assuming
>> $ formatting IS destined to get into Python) $ formatting should then be
>> introduced with all or most of the formatting power it eventually 
>> needs, so
>> that those who want to make their programs Py3K-ready can use $ 
>> formatting
>> to replace all their uses of %(name)s formatting.
> 
> 
> I haven't jumped into this discussion since I thought that
> you were only discussing some new feature which I don't have
> a need for.
> 
> Now if you want to deprecate %(name)s formatting,
> the situation is different: my tie would start jumping up
> and down, doing funny noises :-)
> 
> So just this comment from me: please don't deprecate %(name)s
> formatting. For the rest: I don't really care.

Yes, please don't!

Besides the proposals so far, I'd like to add one,
which I really like a bit, since I used it for
years in an institute with a row of macro languages:

How about

name = "Guido" ; land = "The Netherlands"
"His name is <<name>> and he comes from <<land>>.".sub(locals())

I always found this notation very sharp and readable,
maybe this is just me.
I like to have a notation that is easily parsed, has unique
start and stop strings, no puctuation/whitespace rules
at all.
Any kind of extra stuff like format specifiers, default
values or expressions (if you really must) can be added
with ease.
If people like to use different delimiters, why not:

"His name is <$name$> and he comes from <$land$>.".sub(locals(), 
delimiters=("<$","$>") )

-- 
Christian Tismer             :^)   <mailto:tismer@tismer.com>
Mission Impossible 5oftware  :     Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a     :    *Starship* http://starship.python.net/
14109 Berlin                 :     PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34  home +49 30 802 86 56  pager +49 173 24 18 776
PGP 0x57F3BF04       9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
      whom do you want to sponsor today?   http://www.stackless.com/