[Zope] external and sql methods
Martijn Pieters
mj@antraciet.nl
Wed, 04 Aug 1999 13:50:37 +0200
At 22:08 04/08/99 , ainis wrote:
>Ok, and how about opening files/objects in zope folder with external
>method? For example I have in the same zope folder Book1.txt file which
>I have to parse and pass it to the SQL method. Do I have to supply full
>path: open(/usr/local/Zope bla blabla/Book1.txt....) [I cannot do it
>open('self.Book1.txt'..] or can I somehow open all files/objects in
>current folder without supplying path?
You mean you want to read the contents of a file uploaded to the Zope ODB,
so it's in Zope itself? Or do you mean to read a file from the filesystem
on the server Zope runs on?
The first can be done through the self object, either by referencing it
directly (self.objectName) or, if the id of the object contains illegal
Python characters (like the dot in Book1.txt), you could use getattr(self,
'objectName'). self.__getitem__('objectName') also works.
File objects can be read by accessing their .data attribute. So, you can
access the data on the Book1.txt File object with:
data = getattr(self, 'Book1.txt').data
or
data = self.__getitem__('Book1.txt').data
If you want to access files on your local filesystem, you should indeed
pass in a full path:
file = open(fullPathToFile, 'r')
data = file.read()
file.close
--
Martijn Pieters, Web Developer
| Antraciet http://www.antraciet.nl
| Tel: +31-35-7502100 Fax: +31-35-7502111
| mailto:mj@antraciet.nl http://www.antraciet.nl/~mj
| PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149
------------------------------------------