I discovered I can do this:

    class A(object): pass
    class B(object):
        __class__ = A # <<<< magic

    b = B()
    isinstance(b,A) # returns True (as if B derived from A)
    isinstance(b,B) # also returns True

I have some reasons I may want to do this (I an object with same
methods as a dict but it is not derived from dict and I want
isinstance(x,dict)==True to use it in place of dict in some other
code).

What are the problems with the magic trick above? Why does it work?

massimo


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to