Reading File Object in Script (Python)
Hi, I want to read a File object from ZODB. How can I read the content of the uploaded File object? I must to read it line by line with readlines() Can you show a little code block how to do this? Thanks and greets, Ferhat __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
--On 7. September 2006 01:20:53 -0700 Ferhat Ayaz <ferhatayaz@yahoo.com> wrote:
Hi,
I want to read a File object from ZODB. How can I read the content of the uploaded File object?
Use the read() method.
I must to read it line by line with readlines().
Use read() and split() the data if necessary. -aj
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
participants (3)
-
Andreas Jung -
Dieter Maurer -
Ferhat Ayaz