How do you convert a string obj to a file obj?

Matthew Thorley ruach at chpc.utah.edu
Wed May 4 12:25:54 EDT 2005


I'm writing a web app whereby a user uploads a tar acrhive which is then
opened and processed. My web form reads the file like this:

while 1:
    data = value.file.read(1024 * 8) # Read blocks of 8KB at a time
    if not data: break

which leaves me with data as a string obj. The problem that I have is
that the function that processes the archive expects a file object. So
far the only solution I have found it to write the file to disk and then
read it back.

Is there an easy way to convert data, in the example above into a file
object?

Thanks
-Matthew



More information about the Python-list mailing list