Whatever happened to String Interpolation?
fperez528 at yahoo.com
Fri Nov 30 14:57:08 CET 2001
Andreas Kostyrka wrote:
> What about "%%%(x)s%%" % locals()
I'm looking for _clarity_ in the code. I've already written enough
perl code in my life for things like that.
>> I am a big defender of not extending things unless truly needed,
>> and with time I've learned to do things the 'python way', without
>> saying at every corner 'but language_x has this feature!'. But
>> string handling is the one that *constantly* feels kludgy in an
>> otherwise stunningly clean and elegant language.
> Nope it does not ;)
> Adding magic handling of strings would make another wart in a clean
> and elegant language.
We already have magic strings: r'\....'. Since (char)'...' already
means 'this string is special', pep215 just meant a new special mode
in an already existing framework. We have raw, we'd have raw and
interpolated. It doesn't introduce any new concept into the language,
it only extends an existing one.
>> I felt that pep215 had a clean argument, the extension is very
>> orthogonal to the existing features, and can make a lot of code
>> simply a lot cleaner. I feel those are strong arguments.
> Not really. Python already has:
> 1.) print >>f, data
> 2.) "format" % data
> If you do not want exact formating the first one is quite
>>>> import cStringIO
>>>> print >>x, "Hello World."
> 'Hello World.\n'
This doesn't address the isssue o interpolating values with a clearer
syntax, it's just a different way of doing the same we have today.
>> Well, I can keep dreaming...
> Try Ruby. It's got more perlish features.
I don't want ruby (I've looked at it), I don't want perl (been there,
done that, never again). I like python *a lot*, I just see an
opportunity for a clean way of making it even more convenient in
everyday programming than it already is.
More information about the Python-list