Maric Michaud a écrit :
> Le Jeudi 01 Juin 2006 15:36, Christophe a écrit :
>
>> self.x = self.__class__.f(0)
>
> nope, this will result in a TypeError "unbound method must be called with
> instance as first argument"
Your right :(
staticmethod it is then.
--
http://mail.python.org/mail
Eric Brunel a écrit :
> On Thu, 01 Jun 2006 15:07:26 +0200, bruno at modulix
> <[EMAIL PROTECTED]> wrote:
>
>> Do yourself a favour : use new-style classes.
>> class C(object)
>
>
> I would if I could: I'm stuck with Python 2.1 for the moment (I should
> have mentionned it; sorry for that).
On Thu, 01 Jun 2006 15:07:26 +0200, bruno at modulix <[EMAIL PROTECTED]>
wrote:
> Do yourself a favour : use new-style classes.
> class C(object)
I would if I could: I'm stuck with Python 2.1 for the moment (I should
have mentionned it; sorry for that).
[snip]
>> Basically, I want an optional
Le Jeudi 01 Juin 2006 15:36, Christophe a écrit :
> self.x = self.__class__.f(0)
nope, this will result in a TypeError "unbound method must be called with
instance as first argument"
--
_
Maric Michaud
_
Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Te
Eric Brunel a écrit :
> On Thu, 01 Jun 2006 13:34:53 +0200, Peter Otten <[EMAIL PROTECTED]> wrote:
>
>> Eric Brunel wrote:
>>
>>> My actual question is: why does it work in one case and not in the
>>> other?
>>> As I see it, int is just a function with one parameter, and the
>>> lambda is
>>>
Eric Brunel wrote:
> Hi all,
>
> I just stepped on a thing that I can't explain. Here is some code
> showing the problem:
>
> -
> class C:
Do yourself a favour : use new-style classes.
class C(object)
> f = None
> def __init__(self):
> if self.f is not None:
Eric Brunel wrote:
> On Thu, 01 Jun 2006 13:34:53 +0200, Peter Otten <[EMAIL PROTECTED]> wrote:
>
>> Eric Brunel wrote:
>>
>>> My actual question is: why does it work in one case and not in the
>>> other?
>>> As I see it, int is just a function with one parameter, and the lambda
>>> is
>>> just a
Le Jeudi 01 Juin 2006 13:12, Eric Brunel a écrit :
> Thanks for your explanations, Peter. I'll have to find another way to do
> what I want...
maybe :
class C:
f = None
def __init__(self):
if self.f is not None:
self.x = self.f(0)
else:
self.x = 0
class C2(
On Thu, 01 Jun 2006 13:34:53 +0200, Peter Otten <[EMAIL PROTECTED]> wrote:
> Eric Brunel wrote:
>
>> My actual question is: why does it work in one case and not in the
>> other?
>> As I see it, int is just a function with one parameter, and the lambda
>> is
>> just another one. So why does the
Peter Otten wrote:
> Eric Brunel wrote:
>
>
>>My actual question is: why does it work in one case and not in the other?
>>As I see it, int is just a function with one parameter, and the lambda is
>>just another one. So why does the first work, and not the second? What
>>'black magic' takes place
On 1/06/2006 9:46 PM, Maric Michaud wrote:
> Le Jeudi 01 Juin 2006 13:34, Peter Otten a écrit :
>> A python-coded function has a __get__ attribute, a C-function doesn't.
>> Therefore C1.f performs just the normal attribute lookup while C2.f also
>> triggers the f.__get__(C2(), C2) call via the desc
Maric Michaud wrote:
> Le Jeudi 01 Juin 2006 13:34, Peter Otten a écrit :
>> A python-coded function has a __get__ attribute, a C-function doesn't.
>> Therefore C1.f performs just the normal attribute lookup while C2.f also
>> triggers the f.__get__(C2(), C2) call via the descriptor protocol which
Le Jeudi 01 Juin 2006 13:34, Peter Otten a écrit :
> A python-coded function has a __get__ attribute, a C-function doesn't.
> Therefore C1.f performs just the normal attribute lookup while C2.f also
> triggers the f.__get__(C2(), C2) call via the descriptor protocol which
> happens to return a boun
Eric Brunel wrote:
> My actual question is: why does it work in one case and not in the other?
> As I see it, int is just a function with one parameter, and the lambda is
> just another one. So why does the first work, and not the second? What
> 'black magic' takes place so that int is not mistake
Le Jeudi 01 Juin 2006 13:29, Maric Michaud a écrit :
> this exactly the same as :
>
> def f(self, val) :
> return x != 0
oops,
def f(self, val) :
return val != 0
--
_
Maric Michaud
_
Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +3
Le Jeudi 01 Juin 2006 13:12, Eric Brunel a écrit :
> class C1(C):
>f = int
int is not a function but a type, but it's callable so int(0) return 0.
> class C2(C):
>f = lambda x: x != 0
lambda is a function, applied as a class attribute it becomes a method so it's
called with a first para
Hi all,
I just stepped on a thing that I can't explain. Here is some code showing
the problem:
-
class C:
f = None
def __init__(self):
if self.f is not None:
self.x = self.f(0)
else:
self.x = 0
class C1(C):
f = int
class C2(C):
f
17 matches
Mail list logo