Q
questions?
I am a little confused by an example in python book:
class wrapper:
def __init__(self,object):
self.wrapped=object
def __getattr__(self,attrname):
print "Trace:",attrname
print getattr(self.wrapped,attrname) (*)
return getattr(self.wrapped,attrname) (**)
x=wrapper({"a":1, "b":2})
print x.keys() (**)
(*) will output: <built-in method keys of dict object at 0xb7f0f4f4>
while two (**) statements together will print the keys of the
dictionary which is ['a','b']
why (*) doen't output the same result as (**)?
Thanks
class wrapper:
def __init__(self,object):
self.wrapped=object
def __getattr__(self,attrname):
print "Trace:",attrname
print getattr(self.wrapped,attrname) (*)
return getattr(self.wrapped,attrname) (**)
x=wrapper({"a":1, "b":2})
print x.keys() (**)
(*) will output: <built-in method keys of dict object at 0xb7f0f4f4>
while two (**) statements together will print the keys of the
dictionary which is ['a','b']
why (*) doen't output the same result as (**)?
Thanks