What I am asking may look weird, but here is an example:
I have a class ‘A’
class A:
a=1
other I have class ‘B’
class B:
def __init__(self, obj):
self.obj = obj # obj is any object
Now I use:
first = A()
second = B(first)
isinstance(second, A)
I want step 3 to be true. i.e. whatever object class B is taking, it should add instance of that object type to object.
Is something like this possible in Python?
You can of course override the
__new__and derive your object fromtypeinstead ofobjecteffectively creating a class factory…What you end up doing is very similar to:
Which generates a
class Bderived from A, containing that instance of A() – since this is a function you can pass whatever you fancy in for whatever reason you wish to do so.