[Zope] Reading File Object in Script (Python)

Dieter Maurer dieter at handshake.de
Thu Sep 7 16:18:38 EDT 2006


Ferhat Ayaz wrote at 2006-9-7 01:20 -0700:
> ...
>I want to read a File object from ZODB. How can I read
>the content of the uploaded File object?

Reading a "File" object from ZODB is *VERY* different from
reading a "ZPublisher.HTTPRequest.FileUpload" object.

A "File" object has its data in an attribute named "data".
If the "File" is larger, then "data" is not a string but a
complex data structure (a linked list of "pdata" objects).
You can use "str(File.data)" to get the complete content.

A "FileUpload" object on the other hand behaves very much
like a Python "file" object. Especially, you can use "read",
"tell", "seek", ...

>I must to read it line by line with readlines()

For "FileUpload", readline will probably work too. But I am not
sure. Try it out...



-- 
Dieter


More information about the Zope mailing list