dynamic

Michele Simionato michele.simionato at gmail.com
Wed Jun 15 06:12:07 EDT 2005


Having a class that returns instances
of some other class is horrible, but
since you asked for it:

class A(object): pass
class B(object): pass

class Foo(object):
    def __new__(cls, arg):
        if arg=="a":
            return A()
        else:
            return B()

print Foo("a")
print Foo("b")

             Michele Simionato

P.S. don't do it!




More information about the Python-list mailing list