Re: Multiple constructors

2005-02-07 Thread Caleb Hattingh
Sure, Nick, I agree with you completely. I generally try to make sure that my classes are limited in what they do/provide, so it is not often a problem that a class may need to be instantiated in several very different ways. But your point is well taken. Thanks Caleb -- http://mail.python.org/

Re: Multiple constructors

2005-02-07 Thread Nick Coghlan
Caleb Hattingh wrote: Though Alex indicated differently earlier, I intend to always use an "if" statment inside one constructor to initialise any class in the situation where the arguments may be different in number and type. I don't have the years of experience that Alex has, however, so I

Re: Multiple constructors

2005-02-06 Thread Caleb Hattingh
Hi Philip C++ to Python is a steep 'unlearning' curve... That's worthy of QOTW. I decided not to reply to this thread earlier, but you just convinced me otherwise :) I work in Delphi a lot, which is in a lot of respects very similar to C. I have come to the conclusion that function overloadi

Re: Multiple constructors

2005-02-06 Thread Steven Bethard
Alex Martelli wrote: If you want to do this all the time, you could even build appropriate infrastructure for this task -- a little custom descriptor and metaclass, and/or decorators. Such infrastructure building is in fact fun and instructive -- as long as you don't fall into the trap of *using* s

Re: Multiple constructors

2005-02-06 Thread vincent wehren
Reinhold Birkenfeld wrote: vincent wehren wrote: Philip Smith wrote: Call this a C++ programmers hang-up if you like. I don't seem to be able to define multiple versions of __init__ in my matrix class (ie to initialise either from a list of values or from 2 dimensions (rows/columns)). Even if Py

Re: Multiple constructors

2005-02-06 Thread Philip Smith
Thanks to all of you Some useful ideas in there, even if some of them stretch my current knowledge of the language. C++ to Python is a steep 'unlearning' curve... Phil "Philip Smith" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Call this a C++ programmers hang-up if you like.

Re: Multiple constructors

2005-02-06 Thread Reinhold Birkenfeld
vincent wehren wrote: > Philip Smith wrote: >> Call this a C++ programmers hang-up if you like. >> >> I don't seem to be able to define multiple versions of __init__ in my matrix >> class (ie to initialise either from a list of values or from 2 dimensions >> (rows/columns)). >> >> Even if Pytho

Re: Multiple constructors

2005-02-06 Thread Alex Martelli
Philip Smith <[EMAIL PROTECTED]> wrote: > Call this a C++ programmers hang-up if you like. > > I don't seem to be able to define multiple versions of __init__ in my matrix Indeed, you can never define ``multiple versions'' of the same name in the same scope: one scope + one name -> one object.

Re: Multiple constructors

2005-02-06 Thread Terry Reedy
"Philip Smith" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Call this a C++ programmers hang-up if you like. > > I don't seem to be able to define multiple versions of __init__ in my > matrix Correct. > class (ie to initialise either from a list of values or from 2 dimensions

Re: Multiple constructors

2005-02-06 Thread Leif K-Brooks
Leif K-Brooks wrote: @classmethod def from_pair(self, rows, columns): return Matrix([rows, columns]) # Or with the right argument Er... I'm not sure why I named that argument "self", it should be "cls" if you don't want to confuse anyone reading your code. -- http://mail.python.or

Re: Multiple constructors

2005-02-06 Thread vincent wehren
Philip Smith wrote: Call this a C++ programmers hang-up if you like. I don't seem to be able to define multiple versions of __init__ in my matrix class (ie to initialise either from a list of values or from 2 dimensions (rows/columns)). Even if Python couldn't resolve the __init__ to use on the

Re: Multiple constructors

2005-02-06 Thread Leif K-Brooks
Philip Smith wrote: I don't seem to be able to define multiple versions of __init__ in my matrix class (ie to initialise either from a list of values or from 2 dimensions (rows/columns)). You could either use an if statement with *args: class Matrix(object): def __init__(self, *args):