Using Multiple Constructors

Alex new_name at mit.edu
Fri Aug 3 17:36:43 EDT 2001


import types

Class MyObject:
    Constructor1(self, number):
        pass
    Constructor2(self, string):
        pass

    def __init__(self, initarg):
        
        if type(initarg) == types.StringType:
            self.Constructor1(initarg)
        elif type(initarg) in (types.IntType, 
                               types.FloatType,
                               types.ComplexType):
            self.Constructor2(initarg)

HTH
Alex.



More information about the Python-list mailing list