Python 2.2 properties

Thomas Heller thomas.heller at ion-tof.com
Tue Jan 15 13:35:07 CET 2002


"Steven D. Arnold" <stevena at neosynapse.net> wrote in message news:mailman.1011093687.17603.python-list at python.org...
> Am I misunderstanding how properties work?  It seems that given the
> code below, i.a ought to equal 5 no matter what.  What am I doing
> wrong?
>
> >>> sys.version
> '2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)]'
> >>> class foo:
> ...     def __init__(self):
> ...             self.a = 5
> ...     def seta(self, value):
> ...             self._a = 5
> ...     def geta(self):
> ...             return self._a
> ...     a = property(geta, seta)
> ...
> >>> i = foo()
> >>> i.a
> 5
> >>> i.a = 6
> >>> i.a
> 6

You must derive your class from object:
> >>> class foo(object):

Thomas





More information about the Python-list mailing list