James Stroud wrote:
> If you know what type of object "object" is
> (BTW, a keyword in 2.3 and later, I believe)
Not a keyword, but a builtin as of 2.2.
STeVe
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
> I am a C++ developer with only a little experience using Python. I
> want to create a Python class where by I can construct an instance from
> that class based on one of two different object types.
The approaches I've seen used are to use a new class method as an
alte
On Sunday 08 May 2005 03:28 pm, James Stroud wrote:
> try:
> self.avalue = isinstance.get_avalue()
> except NameError:
> self.avalue = isinstance.get_anothervalue()
I have no idea where I copied those "isinstance"s from. Also, the except
should be an AttributeError. Here is a retr
On Sunday 08 May 2005 03:05 pm, [EMAIL PROTECTED] wrote:
> I am a C++ developer with only a little experience using Python. I
> want to create a Python class where by I can construct an instance from
> that class based on one of two different object types.
>
> For example, if I were programming in
[EMAIL PROTECTED] wrote:
> I am a C++ developer with only a little experience using Python. I
> want to create a Python class where by I can construct an instance from
> that class based on one of two different object types.
>
> For example, if I were programming in C++, I would do the something
I am a C++ developer with only a little experience using Python. I
want to create a Python class where by I can construct an instance from
that class based on one of two different object types.
For example, if I were programming in C++, I would do the something
like the following:
class MyClass
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/
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
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
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
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
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.
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
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.
"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
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
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
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):
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 basis of argument
19 matches
Mail list logo