generate HTML
Scott David Daniels
scott.daniels at acm.org
Mon Nov 14 13:54:26 EST 2005
Jeffrey Schwab wrote:
> s99999999s2003 at yahoo.com wrote:
...
>> def genpage(arg1,arg2):
>> print ''' <div align="right"><font size="-1">BLAH BLAH.....%s %s
>> ''' % (arg1, arg2)
...
>> .... i wish to print all these into a HTML output file so that
>> when i click on it, it shows me the html page. How can i do that?
> ...
> Why not just redirect the output of your Python script from the shell?
> E.g.:
>
> python generate_html.py > output.html
Or you can even do the following Python dance:
def gen_to_file(filename, arg1, arg2):
import sys
former, sys.stdout = sys.stdout, open("output.html", "w")
try:
genpage(arg1, arg2)
finally:
htmlfile, sys.stdout = sys.stdout, former
htmlfile.close()
print 'file %r written' % filename
--Scott David Daniels
scott.daniels at acm.org
More information about the Python-list
mailing list