Modifiying __getattribute__ of an instance

Yaşar Arabacı yasar11732 at
Sat Sep 17 11:10:31 EDT 2011

I am trying to modify __getattribute__() method for an instance, as you may
already know,__getattirbute__ is read-only attribute in Python. What I have
in mind is, create a new object like this:

def create_new_instace(old_instance):
    class temp(old_instance.__class__):
        def __init__(self,*args,**kwargs):
            "Since we will copy an already inited instance"
        def __getattribute__(self,attr):
           # do stuff
    new_instance = temp()
    # magically copy all attrs of old_instance to new_instance
    return new_instance

Is this kind of thing possible?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list