7.4. HTML Inside Python
HTML Inside Python (HIP) is the mirror of Python Inside HTML ; it makes
including HTML code inside Python scripts easier than with print
statements. You can do so using two ways :
- for short chunks of HTML, begin the line with quotes, without a
print
statement : HIP will add the statement for you on executionimport os currentDir=os.getcwd() "Current directory is <b>"+currentDir+"</b>"
- for longer chunks, use the Python multiline string syntax with three
double quotes :
the_smiths={'vocals':'Morrissey', 'guitar':'Johnny Marr', 'the bass guitar':'Andy Rourke', 'the drums':'Mike Joyce'} """ <table border=1> <tr backgroundcolor=green> <td>One of the best pop bands ever</td> </tr> </table> <table> """ for item in the_smiths.keys(): "<tr><td>%s</td><td>%s</td></tr>" %(item,the_smiths[item]) "</table>"