[Python-bugs-list] [ python-Bugs-595032 ] Tutorial: Section 9.6 - error in example
noreply@sourceforge.net
noreply@sourceforge.net
Wed, 14 Aug 2002 05:43:51 -0700
Bugs item #595032, was opened at 2002-08-14 13:43
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=595032&group_id=5470
Category: Documentation
Group: None
Status: Open
Resolution: None
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
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=595032&group_id=5470