Simulating call of instance like a list or tuple
Cesar Douady
cesar.douady at asim.lip6.fr
Mon Jan 14 06:04:55 EST 2002
In article
<Pine.SOL.4.44.0201130026020.2119-100000 at death.OCF.Berkeley.EDU>, "Brett
Cannon" <bac at ocf.berkeley.edu> wrote:
> First, thanks to everyone who replied to my post.
>
> It seems everyone is thinking that I want __repr__ or __str__, which is
> in the right vein, but not quite it. I want the same functionality,
> but I want to be able to return something other than a string. I don't
> think it exists outside of the built-in classes.
>
> -Brett C.
>
I understand you want the same behavior as the *property* when accessing
attributes (i.e. having a get, set and del method).
I am like you and I am about to propose a PEP just to say that properties
must be accepted in local() and globals() just the way they are in
attributes.
Something like :
>>> def myGet(self):
>>> print "got it"
>>> return "whatever"
>>> def mySet(self,value):
>>> print "setting to",value
>>> "whatever code here"
>>> return None
>>>
>>> x=property(myGet,mySet)
>>>
>>> x
got it
whatever
>>> x=3
setting to 3
>>>
More information about the Python-list
mailing list