Outputting strings in html

Stephan Diehl stephan.diehl at gmx.net
Tue Dec 3 13:49:21 EST 2002


Ben wrote:
> Hey all,
> i'm very new to python programming (impressed so far - i love the way it
> handles cgi forms - WAY better than C :), but i'm a bit confused on one 
> or two things....
> 
> variables, unlike C aren't declared with types, right?  so doing
> color = "#FFFF00" would give me a string FFFF00....but how can i use
> that if i'm writting html in a script?
> i want to do something like this:
> 
> print """
> <html><head><title>hello</title></head>
> <body bgcolor=color>
> .....
> """
> but I can't get the string to be displayed?
> i've tried bgcolor="+color+", and searched google for "python """ print
> variable", but haven't found anything of use yet.
> any help for a noob?
> 
> thanks.

use '<body bgcolor="%s">' % color

This just works like printf in C. %s is a placeholder for a string and 
on the right of the '%' is the variable who's value is substituted.




More information about the Python-list mailing list