Sucking in a text file

Chris Gonnerman chris.gonnerman at usa.net
Sat Mar 10 10:53:26 EST 2001


----- Original Message ----- 
From: "Simon Faulkner" <News at Titanic.co.uk>
Subject: Sucking in a text file


> I have a .py cgi script that writes a page to the web and it works!
> 
> To allow the users to customise the out put I would like the script to
> suck in the first part of the page from a text file and then to spit
> this out to the web server.
> 
> Is this easy or do I need to open the file and read each byte in turn?

hdrf = open("my_header.html", "r") # the "r" is not required actually
header = hdrf.read()
hdrf.close()
sys.stdout.write(header)

Hope this helps.






More information about the Python-list mailing list