[Python-bugs-list] [ python-Bugs-595032 ] Tutorial: Section 9.6 - error in example
noreply@sourceforge.net
noreply@sourceforge.net
Wed, 14 Aug 2002 08:28:38 -0700
Bugs item #595032, was opened at 2002-08-14 08:43
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=595032&group_id=5470
Category: Documentation
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Nathan Dimmock (ned21)
Assigned to: Fred L. Drake, Jr. (fdrake)
Summary: Tutorial: Section 9.6 - error in example
Initial Comment:
I couldn't get the following code from the tutorial
(section 9.6) to work. My local guru says the problem
is in the third line and probably used to work in a
previous version of python. (I'm using 2.2.1 on
RH-Linux 2.4.18)
# example code
class VirtualAttributes:
__vdict = None
__vdict_name = locals().keys()[0] # BROKEN
def __init__(self):
self.__dict__[self.__vdict_name] = {}
def __getattr__(self, name):
return self.__vdict[name]
def __setattr__(self, name, value):
self.__vdict[name] = value
# test code (added by user)
db = VirtualAttributes() # create an empty database
db.x = 1
print db.x
Trace:
Traceback (most recent call last):
File "./classTest.py", line 19, in ?
db.x = 1
File "./classTest.py", line 16, in __setattr__
self.__vdict[name] = value
TypeError: object does not support item assignment
----------------------------------------------------------------------
>Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2002-08-14 11:28
Message:
Logged In: YES
user_id=3066
I've removed the obsolete example from Doc/tut/tut.tex 1.169
and 1.156.4.1.2.9.
The rules for private names were introduced well before
Python 2.0, and it is not reasonable for the tutorial to
cater to versions that old.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=595032&group_id=5470