[Zope] How do I write to a text file from Python?

Dieter Maurer dieter at handshake.de
Sun Aug 31 02:56:05 EDT 2008


Jakob Schou Jensen wrote at 2008-8-29 20:11 +0200:
>I would like to create a File object in the and store some text in it from a
>Python script.

It depends what you mean by "File object".

If you mean a Python "file", sitting somewhere on your file system,
then Andreas' advice is helpful.

If you mean a Zope "File" object (an "OFS.Image.File"), then
you would create the object in the standard way for creation
of Zope objects, that is:

   destination.manage_addProducts[<product>].<constructor>(<args>).

For a "File" object, "<product>" is "OFSP" ("Object File System Product"),
"constructor" is "manage_addFile" and the arguments are
"id, file='', title='', precondition='', content_type=''".

"file" is in fact the content that should be stored in your
"File" object. It can be a string or a "file" like object.


-- 
Dieter


More information about the Zope mailing list