Operator overloading and __getattr__
Samuel Kleiner
sam at h41n2fls31o839.telia.com
Mon Dec 22 11:03:03 EST 2003
I'm trying to create methods on method access- but __getattr__ fails
with operator overloading(below) Any suggestions? EG:
class NewM(dict):
def __getattr__(self,name):
def fi(m):
if type(name) in self:
self[type(name)]=self[type(name)].__dict__[name](m)
else:
self[type(name)]=m
return fi
p=int(2)
s=NewM()
print p.__add__(2)
print s.__add__(2)
print p+2
print s+2
Causes TypeError on the last line
--
"I know, there is no Nobel Prize in preternatural biology. That's
because Alfred Nobel's wife was seduced by a vampire." --Andrew Plotkin
More information about the Python-list
mailing list