Whatever happened to String Interpolation?

Andreas Kostyrka andreas at mtg.co.at
Sat Dec 1 06:32:11 EST 2001


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am Mittwoch, 28. November 2001 19:10 schrieb Fernando Pérez:
> A more serious one: dynamic code generation. Just today I had to jump
> through some annoying hoops (like defining x="'%s'" and y='%' and use
> those in a string) to generate code that would include % characters
> but which would first have to be parsed by a %. I know this isn't
> exactly common, though.
What about "%%%(x)s%%" % locals()

> 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.
>
> 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 acceptable:
>>> import cStringIO
>>> x=cStringIO.StringIO()
>>> print >>x, "Hello World."
>>> x.getvalue()
'Hello World.\n'

> Well, I can keep dreaming...
Try Ruby. It's got more perlish features.

Andreas
- -- 
Andreas Kostyrka; Raiffeisenstr. 16/9; 2320 Zwölfaxing
Tel: +43/676/4091256; Fax: +43/1/7065299
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE8CL/AHJdudm4KnO0RAsfuAKDNxz6nibRM5U7qUaB1XBUN6LgKvwCfU2Pz
g5gfuw07Gm3NHrbWA7ePvi0=
=A74K
-----END PGP SIGNATURE-----




More information about the Python-list mailing list