Passing a parent class as an argument?

advertisements

Is it possible to leave a parent class unspecified until an instance is created?
e.g. something like this:

class SomeParentClass:
    # something

class Child(unspecifiedParentClass):
    # something

instance = Child(SomeParentClass)

This obviously does not work. But is it possible to do this somehow?


Have you tried something like this?

class SomeParentClass(object):
    # ...
    pass

def Child(parent):
    class Child(parent):
        # ...
        pass

    return Child()

instance = Child(SomeParentClass)

In Python 2.x, also be sure to include object as the parent class's superclass, to use new-style classes.