how to use more than 1 __init__ constructor in a class ?
Rocco Moretti
roccomoretti at hotpop.com
Thu Jun 23 09:37:26 EDT 2005
Steven D'Aprano wrote:
> On Wed, 22 Jun 2005 12:34:21 -0500, Rocco Moretti wrote:
>
>
>>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 :-)
I think the distinction between just calling other functions and
dispatching is that with dispatching, the function doesn't do any actual
work by itself, but just hands off the work to a different function.
http://www.c2.com/cgi/wiki?DispatchingForDummies
> That's the joys of a mostly self-taught programming knowledge: you miss
> out on all the buzzwords.
Being mostly self taught myself, I have a tendancy to use infrequently
encountered terms in related but technically inappropriate contexts,
confusing the better informed people I deal with. ;-)
More information about the Python-list
mailing list