Changes

Jump to: navigation, search

Libhtml

941 bytes added, 20:37, 9 June 2009
no edit summary
from libhtml import _XMLMS
 
=== Using the Html class as a context manager ===
 
As of Python version 2.5, a new statement has been added to enable you to program within a given context. The "with" statement accomplishes this for you. The Html class supports being used in the "with" statement. That means that you can write code like:
 
with Html('table') as table:
with Html('tbody') as tbody:
table += tbody
with Html('tr') as trow:
tbody += trow
with Html('td') as tcell:
trow += tcell
tcell += 'foobar'
 
which has the advantage that the indentation structure of your program will match the indentation structure of the html file produced by the write() method.
 
Note: If you want to use the "with" statement in programs that may run under Python version 2.5, you must include the following as the first executable statement of your module:
 
from __future__ import with_statement
== Recommended approach ==
70
edits

Navigation menu