Using Multiple Constructors

jjinkins jjinkiins at
Sun Aug 5 00:11:55 CEST 2001

Assuming the class is in a module, why not write functions to act as alternate

def MyObjectNbr(number):
    string = "%s" % number
    return MyObject(string)

Class MyObject:
    def __init__(self, string):
        self.string = string

    Jim Jinkins

Mikhael Loo wrote:

> How do you use multiple constructors in a python class.  I'm guesing that it
> doesn't involve multiple __init__ functions.
> Below is my idea but I'm thinking there must be another method that  is
> evading me.
> Class MyObject:
>     Constructor1(self, number):
>         pass
>     Constructor2(self, string):
>         pass
> Help anyone?

More information about the Python-list mailing list