How do you convert a string obj to a file obj?
Matthew Thorley
ruach at chpc.utah.edu
Wed May 4 12:40:33 EDT 2005
John Abel wrote:
> Matthew Thorley wrote:
>
>> 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
>>
>>
> fileObj = StringIO.StringIO()
> fileObj.write( data )
>
> J
>
I gave that a shot but got this error? Perhaps I misunderstood what kind
of object I needed. Any thoughts?
AttributeError: StringIO instance has no attribute 'rfind'
More information about the Python-list
mailing list