how to use more than 1 __init__ constructor in a class ?

Steven D'Aprano steve at REMOVETHIScyber.com.au
Wed Jun 22 21:25:59 EDT 2005


On Wed, 22 Jun 2005 12:34:21 -0500, Rocco Moretti wrote:

> scott wrote:
>> hi people,
>> 
>> can someone tell me, how to use a class like that* (or "simulate" more 
>> than 1 constructor) :
>> #--

[snip]

> You could also turn __init__ into a dispatch fuction:
> 
> #--
> class myPointClass:
>    def __init__(self, *args):
>      if len(args) <= 2:
>        self.__init_two(*args)
>      if len(args) == 3:
>        self.__init_three(*args)

Oh wow, so that's what I've been doing for years. Dispatching.

And I thought I was just calling other functions :-)

That's the joys of a mostly self-taught programming knowledge: you miss
out on all the buzzwords.


-- 
Steven.




More information about the Python-list mailing list