How do you convert a string obj to a file obj?
Matthew Thorley
ruach at chpc.utah.edu
Wed May 4 15:20:28 EDT 2005
Esben Pedersen 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
>
>
> value.file is a file object. Why don't you give that as an argument?
>
> /Esben
Ok I tried that but I still get this error. Any clue what I need to do?
AttributeError: 'file' object has no attribute 'rfind'
thanks
-Matthew
More information about the Python-list
mailing list