Re: Function mistaken for a method

2006-06-02 Thread Christophe
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

Re: Function mistaken for a method

2006-06-01 Thread Bruno Desthuilliers
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).

Re: Function mistaken for a method

2006-06-01 Thread Eric Brunel
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

Re: Function mistaken for a method

2006-06-01 Thread Maric Michaud
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

Re: Function mistaken for a method

2006-06-01 Thread Christophe
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 >>>

Re: Function mistaken for a method

2006-06-01 Thread bruno at modulix
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:

Re: Function mistaken for a method

2006-06-01 Thread Peter Otten
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

Re: Function mistaken for a method

2006-06-01 Thread Maric Michaud
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(

Re: Function mistaken for a method

2006-06-01 Thread Eric Brunel
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

Re: Function mistaken for a method

2006-06-01 Thread bruno at modulix
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

Re: Function mistaken for a method

2006-06-01 Thread John Machin
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

Re: Function mistaken for a method

2006-06-01 Thread Peter Otten
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

Re: Function mistaken for a method

2006-06-01 Thread Maric Michaud
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

Re: Function mistaken for a method

2006-06-01 Thread Peter Otten
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

Re: Function mistaken for a method

2006-06-01 Thread Maric Michaud
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

Re: Function mistaken for a method

2006-06-01 Thread Maric Michaud
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

Function mistaken for a method

2006-06-01 Thread Eric Brunel
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