[Zope] storing python objects

Jonathan dev101 at magma.ca
Fri Oct 26 08:46:32 EDT 2007


----- Original Message ----- 
From: "Chris Withers" <chris at simplistix.co.uk>
To: "Jonathan" <dev101 at magma.ca>
Cc: <David.Bear at asu.edu>; "zope" <Zope at 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 at 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



More information about the Zope mailing list