storing python objects
I need to run an external method to use some python functions that are restricted within zope. I'm thinking an easy way to get the data back would be to just store basic python objects within zodb; tupples, lists, dictionaries. but I've never seen this documented anywhere. Is it possible to store basic python objects directly in zodb? AND then use a zpt to read the data? I'm thinking a simple thing would be to create an external method that returns a dictionary. Then I could have script call the method, and stored the dictionary on zodb. Then have a zpt publish the dictionary. Is this even easily possible, or are there alternatives to doing something similar? -- David Bear phone: 602-496-0424 fax: 602-496-0955 College of Public Programs/ASU University Center Rm 622 411 N Central Phoenix, AZ 85007-0685 "Beware the IP portfolio, everyone will be suspect of trespassing"
----- Original Message ----- From: "David Bear" <David.Bear@asu.edu> To: "zope" <Zope@zope.org> Sent: Thursday, October 25, 2007 6:19 PM Subject: [Zope] storing python objects
I need to run an external method to use some python functions that are restricted within zope. I'm thinking an easy way to get the data back would be to just store basic python objects within zodb; tupples, lists, dictionaries.
but I've never seen this documented anywhere. Is it possible to store basic python objects directly in zodb? AND then use a zpt to read the data?
I'm thinking a simple thing would be to create an external method that returns a dictionary.
Then I could have script call the method, and stored the dictionary on zodb.
I have done something similar: have an external method store a a list/dictionary value in a property field on a folder, then a future call to the external method retrieves that property field and uses 'eval' to convert it back to a list/dictionary (it is stored as a string). *** Warning: You need to be 100% sure you know what is in the list/dictionary if you are going to use 'eval' though! The other approach I have used is to create a dead simple Zope product that just defines an object class (which contains lists, dictionaries, etc) and then have the external method store these objects directly in the ZODB. Jonathan
Jonathan wrote:
----- Original Message ----- From: "David Bear" <David.Bear@asu.edu>
I need to run an external method to use some python functions that are restricted within zope. I'm thinking an easy way to get the data back would be to just store basic python objects within zodb; tupples, lists, dictionaries.
Why not just have the external method return the results and call the external method from a python script?
but I've never seen this documented anywhere. Is it possible to store basic python objects directly in zodb? AND then use a zpt to read the data?
Yes. in your external method: self.somefolder.mydata = {'whatever':'somevalue'}
I have done something similar: have an external method store a a list/dictionary value in a property field on a folder, then a future call to the external method retrieves that property field and uses 'eval' to convert it back to a list/dictionary (it is stored as a string).
Why on *earth* would you do that?! Why not just store the actual value rather than fiddling around with strings and eval?
The other approach I have used is to create a dead simple Zope product that just defines an object class (which contains lists, dictionaries, etc) and then have the external method store these objects directly in the ZODB.
You can either store in the root of the zodb, hang off an existing object, or just use SimpleItem. cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
----- Original Message ----- From: "Chris Withers" <chris@simplistix.co.uk> To: "Jonathan" <dev101@magma.ca> Cc: <David.Bear@asu.edu>; "zope" <Zope@zope.org> Sent: Friday, October 26, 2007 8:17 AM Subject: Re: [Zope] storing python objects
Jonathan wrote:
----- Original Message ----- From: "David Bear" <David.Bear@asu.edu>
I need to run an external method to use some python functions that are restricted within zope. I'm thinking an easy way to get the data back would be to just store basic python objects within zodb; tupples, lists, dictionaries.
Why not just have the external method return the results and call the external method from a python script?
but I've never seen this documented anywhere. Is it possible to store basic python objects directly in zodb? AND then use a zpt to read the data?
Yes.
in your external method:
self.somefolder.mydata = {'whatever':'somevalue'}
I have done something similar: have an external method store a a list/dictionary value in a property field on a folder, then a future call to the external method retrieves that property field and uses 'eval' to convert it back to a list/dictionary (it is stored as a string).
Why on *earth* would you do that?! Why not just store the actual value rather than fiddling around with strings and eval?
If you want to be able to inspect the list/dictionary via the ZMI then storing the list/dict as a property on an object (eg. folder) allows you to do that - but if you do not need access via the ZMI, then storing the list/dict directly on the object will be more efficient. Jonathan
On Thu, Oct 25, 2007 at 03:19:10PM -0700, David Bear wrote:
but I've never seen this documented anywhere. Is it possible to store basic python objects directly in zodb?
http://www.zope.org/Documentation/Books/ZDG/current/Persistence.stx -- Paul Winkler http://www.slinkp.com
--On 25. Oktober 2007 15:19:10 -0700 David Bear <David.Bear@asu.edu> wrote:
I need to run an external method to use some python functions that are restricted within zope. I'm thinking an easy way to get the data back would be to just store basic python objects within zodb; tupples, lists, dictionaries.
If you need to have this stored on a per-user basis: use sessions. If you need to have this stored as a cache: use one of the existing caches in Zope (RAMCache). -aj
David Bear wrote:
I need to run an external method to use some python functions that are restricted within zope. I'm thinking an easy way to get the data back would be to just store basic python objects within zodb; tupples, lists, dictionaries.
but I've never seen this documented anywhere. Is it possible to store basic python objects directly in zodb? AND then use a zpt to read the data?
I'm thinking a simple thing would be to create an external method that returns a dictionary.
Then I could have script call the method, and stored the dictionary on zodb.
Then have a zpt publish the dictionary.
Is this even easily possible, or are there alternatives to doing something similar?
Google for 'PersistentList' and/or 'PersistentMapping' Raphael
participants (6)
-
Andreas Jung -
Chris Withers -
David Bear -
Jonathan -
Paul Winkler -
Raphael Ritz