Inserting values into HTML output

Published: Wednesday, Dec 26, 2007 Last modified: Monday, Dec 9, 2024

use

print '<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. http://groups.google.com/groups?q=Outputting+strings+in+html&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=mailman.1038943265.6652.python-list%40python.org&rnum=1 And how about using a dictionary/hash?

hendry@bogrund-14:~$ python2

Python 2.2.2 (#1, Nov 22 2002, 17:25:34)

[GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-112)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> previous, word_id, occurance = 'cow', 'dog', 'cat'

>>> print "Entering: %s " % (previous, word_id, occurance)

Traceback (most recent call last):

File “”, line 1, in ?

TypeError: not all arguments converted

>>> print "Entering: %s " % (previous, word_id, occurance)

Traceback (most recent call last):

File “”, line 1, in ?

TypeError: not all arguments converted

>>> previous

'cow'

>>> word_id

'dog'

>>> print "Entering: %s, %s, %s " % (previous, word_id, occurance)

Entering: cow, dog, cat

>>>