Re: [Zope3-Users] Syncing two attributes

2005-06-24 Thread Shane Hathaway
Florian Lindner wrote:
> Hello,
> I've one attribute A which is exposed via the Interface. Another internal 
> attribute B should be in sync with it. So everytime A changes I want a 
> function to be called. 
> 
> I think (solving another error stands before testing it) with __setattr__:
> 
> def __setattr__(self, name, value):
> if name == "expirationTime":
> self.expTimeDelta = datetime.timedelta(minutes = value)
> 
> self.__dict__[name] = value
> 
> But I really don't like that way? Is there elegant, more zope-like solution? 
> Or is this the way to do it?

Would a property work?

class MyClass(object):

def getExpirationTime(self):
return self._expirationTime

def setExpirationTime(self, value):
self.expTimeDelta = datetime.timedelta(minutes = value)
self._expirationTime = value

expirationTime = property(getExpirationTime, setExpirationTime)

Shane
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] Syncing two attributes

2005-06-24 Thread Florian Lindner
Hello,
I've one attribute A which is exposed via the Interface. Another internal 
attribute B should be in sync with it. So everytime A changes I want a 
function to be called. 

I think (solving another error stands before testing it) with __setattr__:

def __setattr__(self, name, value):
if name == "expirationTime":
self.expTimeDelta = datetime.timedelta(minutes = value)

self.__dict__[name] = value

But I really don't like that way? Is there elegant, more zope-like solution? 
Or is this the way to do it?

Thanks,

Florian
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users