On Jun 18, 3:55 pm, Christoph Groth wrote:
> Bruno Desthuilliers writes:
> > Anyway: the simplest solution here is to replace the call to your Base
> > class with a call to a factory function. I'd probably go for something
> > like (Q&D untested code and other usual warnings) :
>
> > (...)
>
> Ye
Christoph Groth wrote:
Dear all,
sometimes it is handy to have a function which can take as argument
anything which can be converted into something, e.g.
def foo(arg):
arg = float(arg)
# ...
I would like to mimic this behavior of float for a user-defined type,
e.g.
def bar(arg):
Steven D'Aprano writes:
> On Fri, 18 Jun 2010 16:30:00 +0200, Christoph Groth wrote:
>
>> If other is of type Base already, just "pass it on". Otherwise,
>> construct an instance of Base from it.
>>
>> import
>> numpy as np
>>
>>
Bruno Desthuilliers writes:
> Anyway: the simplest solution here is to replace the call to your Base
> class with a call to a factory function. I'd probably go for something
> like (Q&D untested code and other usual warnings) :
>
> (...)
Yeah, that will do what I want.
My confusion arose from t
On Fri, 18 Jun 2010 16:30:00 +0200, Christoph Groth wrote:
> If other is of type Base already, just "pass it on". Otherwise,
> construct an instance of Base from it.
>
> import
> numpy as np
>
> class Base:
> def __init__(self
On 6/18/10 3:51 AM, Christoph Groth wrote:
> sometimes it is handy to have a function which can take as argument
> anything which can be converted into something, e.g.
[snip]
> I would like to mimic this behavior of float for a user-defined type,
> e.g.
[snip]
> Now I wonder what is the most pytho
Bruno Desthuilliers a écrit :
Christoph Groth a écrit :
Bruno Desthuilliers writes:
(snip)
In C++
Forget about C++ - Python is a different beast !-)
Still, it is useful and interesting to compare languages.
Indeed. But you have to understand enough of a language to compare it
with ano
Christoph Groth a écrit :
Bruno Desthuilliers writes:
It seems to me that in this way I might get problems when I pass an
instance of Derived_from_my_type to bar, as it will become an
instance of My_type.
The instance you pass to bar won't "become" anything else. You create
a new My_type inst
Bruno Desthuilliers writes:
>> It seems to me that in this way I might get problems when I pass an
>> instance of Derived_from_my_type to bar, as it will become an
>> instance of My_type.
>
> The instance you pass to bar won't "become" anything else. You create
> a new My_type instance from the D
Christoph Groth a écrit :
Dear all,
sometimes it is handy to have a function which can take as argument
anything which can be converted into something, e.g.
def foo(arg):
arg = float(arg)
# ...
I would like to mimic this behavior of float for a user-defined type,
e.g.
def bar(arg):
Dear all,
sometimes it is handy to have a function which can take as argument
anything which can be converted into something, e.g.
def foo(arg):
arg = float(arg)
# ...
I would like to mimic this behavior of float for a user-defined type,
e.g.
def bar(arg):
arg = My_type(arg)
#
11 matches
Mail list logo