Alternative to python -u for binary upload to cgi on windows?

Cameron Walsh cameron.walsh at gmail.com
Fri Dec 14 02:58:26 EST 2007


Hi all,

Using a python cgi script such as the one below to handle uploaded 
binary files will end up with a truncated file (truncates when it hits 
^Z) on Windows systems.  On linux systems the code works and the file is 
not truncated.

One solution for Windows is to use the -u flag, i.e.
#!C:\Python\python.exe -u

Is there another fix that doesn't require python to be run in unbuffered 
mode?  What performance hits would I expect for running in unbuffered mode?

Best regards,

Cameron.


Example code:

import cgi, os.path as path
form = cgi.FieldStorage()
new_file = form.getvalue("new_file",None)
if new_file is not null:
   fname = path.split(form["new_file"].filename)[-1]
   fle = open(fname,"wb")
   fle.write(new_file)
   fle.close()



More information about the Python-list mailing list