example from the book

questions? universal_used at hotmail.com
Thu Jan 18 03:37:41 CET 2007


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




More information about the Python-list mailing list