[ python-Bugs-1175022 ] property example code error

SourceForge.net noreply at sourceforge.net
Sat Jun 25 22:08:09 CEST 2005


Bugs item #1175022, was opened at 2005-04-01 22:09
Message generated for change (Comment added) made by birkenfeld
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1175022&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Documentation
Group: Python 2.4
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: John Ridley (ojokimu)
>Assigned to: Reinhold Birkenfeld (birkenfeld)
Summary: property example code error

Initial Comment:
The example code for 'property' in lib/built-in-funcs.html may 
produce an error if run "as is": 
 
Python 2.4.1 (#1, Mar 31 2005, 21:33:58) 
[GCC 3.4.1 (Mandrakelinux (Alpha 3.4.1-3mdk)] on linux2 
>>> 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.") 
... 
>>> c=C() 
>>> c.x 
Traceback (most recent call last): 
  File "<stdin>", line 1, in ? 
  File "<stdin>", line 2, in getx 
AttributeError: 'C' object has no attribute '_C__x' 
 
The same goes for 'del c.x' (although not 'c.x = 0', of course). 
 
A more "typical" way of defining managed attributes would be to 
include an 'init' as follows: 
 
class C(object): 
    def __init__(self): self.__x = None 
    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.") 
 
 

----------------------------------------------------------------------

>Comment By: Reinhold Birkenfeld (birkenfeld)
Date: 2005-06-25 22:08

Message:
Logged In: YES 
user_id=1188172

Thanks for the report; fixed as Doc/lib/libfuncs.tex r1.184,
r1.175.2.4.

----------------------------------------------------------------------

Comment By: Sean Reifschneider (jafo)
Date: 2005-04-06 05:33

Message:
Logged In: YES 
user_id=81797

I agree, adding the __init__ to set a value would be useful.  +1

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1175022&group_id=5470


More information about the Python-bugs-list mailing list