Variables in strings..

Richard Brodie R.Brodie at rl.ac.uk
Mon Jul 24 06:51:03 EDT 2000


"Gabriel Ambuehl" <gabriel_ambuehl at buz.ch> wrote in message
news:81324605608.20000724121203 at buz.ch...
> 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):

It's true:
    Python doesn't go out of its way to make common tasks easy for you
in the language itself. It's more like Java in that way: knowing the right
classes and methods to use is the path to enlightment.

I recommend you have a look at the Python web application pages. I'm
pleased with using HTMLgen.

from HTMLgen import *

mapping = {'name' : 'Legion'}
print StringTemplate('My name is {name}', mapping)
print Strong(StringTemplate('My name is {name}', mapping))
print BasicDocument(Strong(StringTemplate('My name is {name}', mapping)))

My name is Legion
<STRONG>My name is Legion</STRONG>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>....





More information about the Python-list mailing list