Variables in strings..

Gabriel Ambuehl gabriel_ambuehl at buz.ch
Mon Jul 24 06:12:03 EDT 2000


Hello,
after switching from Perl to Python because I encountered serious
problems when it came to the maintenance of the Perl code, I begging
for a solution to the following: In Perl, it's very easy to embed a
variable within a string for output (and as my main use for Python is
CGI, I'm doing that rather often):
print "Hello $name"
would do the job. Now the only solution I could find in Python was
this awful
print "Hello %(name)s" % var()
syntax which, after all, doesn't even seem to support lists as
print "Hello %(name[1])s" % var()
just raises a KeyError. May anyone point me to some more comfortable
ways than just endless concatenation of strings and lists which doesn't really
help for readibility (which is one of the main points why I'm
switching from Perl to Python)?

  


Best regards,
 Gabriel






More information about the Python-list mailing list