Allen Huang wrote at 2006-12-23 22:27 -0800:
>I've being trying different things for the pass day
>1. I put the shapefile directly in the Extensions with the external method and
>it work fine
> import shapelib, dbflib
> def readshp():
> shp = shapelib.ShapeFile('taiwan1.shp')
This means, that "ShapeFile" is Zope unaware and will
interpret its argument as a filepath (maybe relative to the current working
The above will work when there is a 'taiwan1.shp' file in the
directory of the so called "INSTANCE_HOME" (which is Zope's usual
current working directory).
In an "External Method" (or other trusted code), you can use
Python's file operations to write files. E.g. you can create
'taivan1.shp' as follows:
f = open('taiwan1.shp', 'wb')
Be warned however, that Zope is a multithread application. Therefore,
it is dangerous to use fixed file names (one thread may overwrite
the file created in a different thread). You probably would want to
have the files created with functions you find in Python's "tempfile"
In case the file you want to precess it a Zope "File" object "f"
(a file in the ZODB), then, you can access its data via
"str(f.data)" (and write this to a file on the file system).
In case, the file you want to precess is updated via a POST request,
it will be turned into a "ZPublisher.HTTPRequest.FileUpload" objects
which behaves like a Python file object (with some additional methods
and attributes). Especially, you can use "f.read()" to read its content.
Zope maillist - Zope@zope.org
** No cross posts or HTML encoding! **
(Related lists -