general class functions
syd
syd.diamond at gmail.com
Tue Nov 2 13:09:50 EST 2004
Many many thanks, Andrea and Kent!
To keep changes to calls in my current code to a minimum, I'm hoping I
can encode Andrea's "on-the-fly" get function. I added Andrea's
__getattr__ to my Library() class, populated the class with a few
nations, and tried:
>>> library.get_continent('Europe')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "foo.py", line 16, in __getattr__
return self.__dict__[name]
KeyError: '__repr__'
I then commented out lines 15 and 16...
#else:
#return self.__dict__[name]
... and re-ran.
>>> library.get_continent('Europe')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: 'NoneType' object is not callable
I tweaked a bit, but I could not get to the bottom of this problem. I
see the logic here (and it's brilliant I should add, Andrea), but I'm
not sure what is wrong.
Ideas?
More information about the Python-list
mailing list