access to other zope objects in __setstate__
hello ! Almost everything is in the subject: i would like to access to a portal tool in the __setstate__ method for an object, but it seems that when this method is called 'self' isn't the acquisition wrapper, so I get an AttributeError. What's the good place to access to other zope objects when an instance is loaded ? TIA -- Sylvain Thénault LOGILAB, Paris (France). http://www.logilab.com http://www.logilab.fr http://www.logilab.org
Sylvain Thénault wrote:
What's the good place to access to other zope objects when an instance is loaded ?
None at all, I think. What are you trying to accomplish, more specifically? There probably is a better way.
Sylvain Thénault wrote:
hello !
Almost everything is in the subject: i would like to access to a portal tool in the __setstate__ method for an object,
I can almost 100% garuantee you that you shouldn't be implementing __setstate__. What are you trying to do? Chris
On Tuesday 10 June à 14:12, Chris Withers wrote:
Sylvain Thénault wrote:
hello !
Almost everything is in the subject: i would like to access to a portal tool in the __setstate__ method for an object,
I can almost 100% garuantee you that you shouldn't be implementing __setstate__.
What are you trying to do?
do you mean that __setstate__ should never be overriden or that I must do something wrong that could be done in another way ? I used __setstate__ to build a non persistent attribute from some persistent data in my object. I've discussed with Lennart Regebro about my problem and I've finished by putting all my setstate code in a method which should be called instead of directly access to the attribute, so the attribute is built on the first call. regards -- Sylvain Thénault LOGILAB, Paris (France). http://www.logilab.com http://www.logilab.fr http://www.logilab.org
Sylvain Thénault wrote:
do you mean that __setstate__ should never be overriden
There are incredibly few situations where it's a good idea to override __setstate__...
I used __setstate__ to build a non persistent attribute from some persistent data in my object.
I'd suggest using ComptuedAttributes or Python 2.2's 'properties' instead...
I've discussed with Lennart Regebro about my problem and I've finished by putting all my setstate code in a method which should be called instead of directly access to the attribute, so the attribute is built on the first call.
That's not how __setstate__ works ;-) cheers, Chris
participants (3)
-
Chris Withers -
Lennart Regebro -
Sylvain Thénault