[Tutor] Documentation on properties

Kent Johnson kent_johnson at skillsoft.com
Wed Sep 29 11:50:31 CEST 2004


Tony,

x is a property of the class, not of an instance of the class. That's why 
there is no self. The name 'x' is bound in the namespace of the class. This 
is actually what happens when you define a method, too - the method is a 
property of the class, it's name is bound in the class namespace.

In fact there is no name 'self' at the point where x is defined; if you 
changed it to self.x you would get an error.

Kent

At 06:15 PM 9/28/2004 -0700, Tony Cappellini wrote:


>The following is straight out of the python documentation
>
>  property( [fget[, fset[, fdel[, doc]]]])
>
>Return a property attribute for new-style classes (classes that derive
>from object).
>fget is a function for getting an attribute value, likewise fset is a
>function for setting, and fdel a function for del'ing, an attribute.
>Typical use is to define a managed attribute x:
>
>
>class C(object):
>     def getx(self): return self.__x
>     def setx(self, value): self.__x = value
>     def delx(self): del self.__x
>     x = property(getx, setx, delx, "I'm the 'x' property.")
>
>
>
>
>
>Why is x not referred to as self.x in the x=property(getx, setx, delx, "")
>  line ?
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list