Overloaded Constructors?!?

andrea_gavana at tin.it andrea_gavana at tin.it
Sun Mar 20 17:29:10 EST 2005


Hello Kent,

   thank you a lot for your answer. I was starting to think that my question
was a little bit strange to obtain an answer...
 
>This is a strange design. My first reaction is, why do you want to do that?
Maybe you >should split the class in two?

You are right. The problem is that this is not my code. Someone else has
written it and, since it is a useful widget to have in a wxPython GUI, I
was trying to port it to Python. I don't want to mess with things like SWIG,
because this widget (compiled in C++) is not portable through all platforms,
while pure Python code should be.
I could split the class in two, but I would like to keep the class/functions
definitions as closer as possible to the original one.

>Next, there
>> are a lot of functions that, depending on the variable _type, return
properties
>> of the wx.Window or of the line. I would like to keep the same names
for
>> classes/methods, so it would be useful to have the same class with 2
different
>> "initializations".

>One way to do this in Python is to have a single constructor that looks
at the type / >number of arguments to figure out what it is supposed to
do. 

I am trying to figure it out using something like:

def __init__(self, parent, **kw):

and processing the keyword args, but it does not satisfy me very much...

>Another way is to make two factory methods that 
>create instances of the class and do the correct initialization.

I am sorry to be so tedious, but I am still quite a newbie in Python...
could you please provide a very small example of your last sentence? Looks
quite interesting...

Thank you a lot.

Andrea.






More information about the Python-list mailing list