translate txt into HTML

Peter Hansen peter at engcorp.com
Tue Jan 21 09:11:53 EST 2003


Natacha wrote:
> 
> We have to create a program allowing to go to seek two textual files
> bruts(.txt), but we would like to translate them into HTML.
> 
> we think that a parser should be used, but we do not know how to make!

To help you clarify your requirements, I offer this first version which
meets your requirements as stated.  What aspect of this do you find
insufficient?  If you can explain that, we can help you with a more
suitable solution, perhaps involving the StructuredText concept...

text = open('afile.txt').read()
htmlFile = open('afile.html', 'w')
print >>htmlFile, '<html><head><title>A file</title></head>'
print >>htmlFile, '<body><pre>%s</pre></body></html>' % text
htmlFile.close()

-Peter




More information about the Python-list mailing list