[Zope-CMF] How to read/write files from Zope??
Lennart Regebro
regebro at nuxeo.com
Wed Oct 27 05:43:16 EDT 2004
(This is not A CMF problem, so further discussion should be on
zope at zope.org)
Sheila María wrote:
> Hi!!
> I want to save some information of my Zope, exactly, I want to
> save the state and the Id, like lists, of my PCNG, because later
> (after to have imported and to have exported), I want to restore it.
> Well, I've created a Python Script avec le code:
> listIds = []
> listStatus = []
>
> rows = context.pcng_catalog(meta_type="issue")
> for r in rows:
> issue=r.getObject()
> listStatus.append(issue.status())
> listIds.append(issue.getId())
>
> # Now, I try to write into a file
> f = open('EstadosIdsAntesExportar', "w")
> f.write(listIds)
> f.write(listStatus)
> f.close()
>
> return 1
>
> Well, I have an error with "f.open()", what does I have to do for
> to include it??.
You can't write to disk from Python scripts. That's a security feature,
to prevent people with access to the webserver to change things on your
server disk. If you have to write to a file you need to use disk based
bython code, either a disk-based Zope product or an "external method".
However, Zope includes an import export function, maybe you can use that?
> Too, I have seen that in Zope there is an object "File", but, how
> can I write or read to/from it??
The File object, as most Zope objects, are for things stored in the
ZODB. So the File object is there to let you store a file (like a word
file or a sound file) in the ZODB.
More information about the Zope-CMF
mailing list