At 11:38 am -0700 4/8/99, ainis wrote:
Is there any way to call sql method from external method?
Yes. def dopey_example(self): for the_item in self.your_ZSQL_method(param1=your_val, param2=your_val2): do_interesting_things_with(the_item) 'self' is your link to the Zope system (ie if you have a property called 'quote', then self.quote will obtain that for you). tone ------ Dr Tony McDonald, FMCC, Networked Learning Environments Project http://nle.ncl.ac.uk/ The Medical School, Newcastle University Tel: +44 191 222 5888 Fingerprint: 3450 876D FA41 B926 D3DD F8C3 F2D0 C3B9 8B38 18A2
Tony McDonald wrote:
At 11:38 am -0700 4/8/99, ainis wrote:
Is there any way to call sql method from external method?
Yes.
def dopey_example(self): for the_item in self.your_ZSQL_method(param1=your_val, param2=your_val2): do_interesting_things_with(the_item)
'self' is your link to the Zope system (ie if you have a property called 'quote', then self.quote will obtain that for you).
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? And one more question- how do I make a form that allows to upload files to some zope folder?
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 ------------------------------------------
participants (3)
-
ainis -
Martijn Pieters -
Tony McDonald