From: O'Brien-Strain, E. <eo...@ex...> - 2002-03-21 21:34:57
|
Another idiom is to use one of the dictionaries that the language provides such as "globals()" or the "__dict__" attribute of an object. For example: title = "My title" body = "Blah, blah" print """ <html> <head> <title>%(title)s</title> </head> <body>%(body)s</body> </html>""" % globals() __ Eamonn O'Brien-Strain HP Labs eo...@hp... ======================================================== > From: Ype Kingma [mailto:yk...@xs...] [...] > my = {} > my['title'] = "My title" > my['body'] = "Blah, blah" > print """ > <html> > <head> > <title>%(title)s</title> > </head> > <body>%(body)s</body> > </html>""" % my ========================================================== > From: Brad Cox [mailto:bc...@vi...] [...] > Does python have a way of interpolating variables into strings, along > the lines of this perl example? > > my $title = "My title"; > my $body = "Blah, blah"; > print """ > <html> > <head> > <title>$title</title> > </head> > <body>$body</body> > </html>""" |