Modifiying __getattribute__ of an instance

Yaşar Arabacı yasar11732 at gmail.com
Sat Sep 17 17:10:31 CEST 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"
            pass
        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?
-- 
http://yasar.serveblog.net/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110917/f20885a7/attachment.html>


More information about the Python-list mailing list