[Python-Dev] Example for "property" violates "Python is not a one pass compiler"

Edward C. Jones edcjones at comcast.net
Mon Sep 5 18:04:33 CEST 2005


Here is an example from the "Python Library Reference", Section 2.1 
"Built-in Functions":

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.")

It works. But if I put the property statement first:

class C(object):
     x = property(getx, setx, delx, "I'm the 'x' property.")
     def getx(self): return self.__x
     def setx(self, value): self.__x = value
     def delx(self): del self.__x

I get the error:
     NameError: name 'getx' is not defined

Does this violate the principle "Python is not a one pass compiler"? 
Normally I can use any method of a class anywhere in the definition of 
the class.



More information about the Python-Dev mailing list