Printing the arguments of an attribute in a class

vsoler vicente.soler at gmail.com
Sun Feb 28 15:42:00 CET 2010


I have a class that is a wrapper:

class wrapper:
    def __init__(self, object):
        self.wrapped = object
    def __getattr__(self, attrname):
        print 'Trace: ', attrname
        #print arguments to attrname, how?
        return getattr(self.wrapped, attrname)

I can run it this way:

>>> x = wrapper([1,2,3])
>>> x.append(4)
Trace:  append
>>> x.wrapped
[1, 2, 3, 4]

I am able to capture the attribute name to x (that is, append).
However, I do not know how to capture and print all of its arguments
(in this case number 4).

How should I proceed?

Thank you



More information about the Python-list mailing list