Having problems with reading file in Python CGI
kiana.toufighi at utoronto.ca
Mon Jun 26 20:49:44 CEST 2006
I have a simple CGI program that allows that user to upload a file.
However, since accessing the the value of the uploaded file using the
value attribute or the getvalue() method reads the entire file in memory
as a string which is not what I want I'm making use of the file module.
The problem is that all the my checks including "assert fileStream.file
in not None" return true however readline() does not return the next
line of the fileStream.file object! What am I doing wrong? Here's my code:
Here's my code:
dataFile = form['data_file']
fileproc = redrev.FileStreamProcessor()
dataLines = fileproc.readStream(dataFile)
def readStream(self, fileStream):
'''readStream: reads a stream of input returns a list of lines'''
# list to hold data lines
fileLines = 
# make sure that the stream has been provided
assert fileStream.file is not None
except Exception, e:
"No input to process"
# use filestream object to get uploaded file's lines one by one
line = fileStream.file.readline()
if not line:
# process and store the line
More information about the Python-list