I'm using "new style" classes in Python 2.6 and am having trouble with __getattr__ in a subclass.
If the subclass implements like such...
def __getattr__(self, name):
if self.__folderDict.has_key(name):
if name == 'created':
return doSomethingSpecial(self.__folderDict[name])
return self.__folderDict[name]
else:
raise AttributeError()
It's not clear to me why my attribute exception gets thrown for a reference to __name__ ?
My understand is that __getattr__ should not even get called and that __name__ should be fullfilled by __getattribute__ since I'm using new style?
Here's a more complete example...
class Base(object):
@staticmethod
def printMsg(msg, var):
print msg + str(var)
return
def printName(self):
Base.printMsg('#', self.__name__)
return
class Derived(Base):
def __getattr__(self, name):
if self.__testDict.has_key(name):
return self.__testDict[name]
else:
raise AttributeError()
__testDict = {'userid': 4098}
d = Derived()
print d.userid
d.printName()
The result is...
4098
Traceback (most recent call last):
File "D:/.../Scratch/scratch01.py", line 24, in <module>
d.printName()
File "D:/.../Scratch/scratch01.py", line 17, in __getattr__
raise AttributeError()
AttributeError