[Tutor] properties not working in 2.2

Gregor Lingl glingl@aon.at
Tue, 18 Dec 2001 07:29:20 +0100


My installation of Python 2.2c1 definitely
doesn't show this (or any other) error-massage
when running your example

instead, I got:

>>> huch = C()
hello world
>>> huch.x
get called
0
>>>

but what is property - and what is it for?

Gregor

----- Original Message -----
From: "karthik Guru" <karthikg@aztec.soft.net>
To: <tutor@python.org>
Sent: Tuesday, December 18, 2001 6:09 AM
Subject: [Tutor] properties not working in 2.2


> hi all,
>
> http://www.python.org/2.2/descrintro.html#property
>
> there is an example to use properties which is not workign for me under
> Python 2.2a1
>
> class C(object):
>     def __init__(self):
>         print "hello world"
>         self.__x = 0
>     def getx(self):
>         print "get called"
>         return self.__x
>     def setx(self, x):
>         print "set called"
>         if x < 0: x = 0
>         self.__x = x
>     x = property(getx,setx,None,"this is property")
>
>
> this is the trace....
>
>   File "test.py", line 13, in C
>     x = property(getx,setx,None,"this is property")
> NameError: name 'property' is not defined
>
> can someone tell me as what's wrong here? ..python2.2 a1 does not have
this
> feature??
>
> thanx,
> karthik
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>