Re: difference between class methods and instance methods

2005-02-18 Thread Steven Bethard
Duncan Booth wrote: Diez B. Roggisch wrote: Duncan Booth wrote: Bound methods get created whenever you reference a method of an instance. That did escape me so far - interesting. Why is it that way? I'd expect that creating a bound method from the class and then storing it in the objects dictionary

Re: difference between class methods and instance methods

2005-02-18 Thread Antoon Pardon
Op 2005-02-18, Diez B. Roggisch schreef <[EMAIL PROTECTED]>: >> This is badly wrong. John was correct. >> >> Bound methods get created whenever you reference a method of an instance. >> If you are calling the method then the bound method is destroyed as soon >> as the call returns. You can have as

Re: difference between class methods and instance methods

2005-02-18 Thread Duncan Booth
Diez B. Roggisch wrote: >> This is badly wrong. John was correct. >> >> Bound methods get created whenever you reference a method of an >> instance. If you are calling the method then the bound method is >> destroyed as soon as the call returns. You can have as many different >> bound methods cre

Re: difference between class methods and instance methods

2005-02-18 Thread Diez B. Roggisch
> This is badly wrong. John was correct. > > Bound methods get created whenever you reference a method of an instance. > If you are calling the method then the bound method is destroyed as soon > as the call returns. You can have as many different bound methods created > from the same unbound meth

Re: difference between class methods and instance methods

2005-02-18 Thread Duncan Booth
John wrote: >>inst = C() >>f1 = inst.foo >>f2 = inst.foo >>f1, f2 >> >> (>, > method C.foo of <__main__.C instance at 0x00B03F58>>) >> > > I just wanted to interject, although those two hex > numbers in the above line are the same, calling > id() on f1 and f2 produces two *different* numbers, >

Re: difference between class methods and instance methods

2005-02-18 Thread Antoon Pardon
Op 2005-02-17, Diez B. Roggisch schreef <[EMAIL PROTECTED]>: > John wrote: >> ... hmm... bound methods get created each time you make >> a call to an instance method via an instance of the given class? > > No, they get created when you create an actual instance of an object. I'm not so sure about

Re: difference between class methods and instance methods

2005-02-17 Thread Terry Reedy
"John M. Gabriele" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > And if anyone's *really* daring: > Where do the so-called "static methods" fit into all this? > By the name of them, it sounds like the same thing as class > methods... No, not at all. So called 'static methods' ar

Re: difference between class methods and instance methods

2005-02-17 Thread John
Duncan Booth wrote: [snip] Bound methods get created whenever you reference a method of an instance. If you are calling the method then the bound method is destroyed as soon as the call returns. You can have as many different bound methods created from the same unbound method and the same instan

Re: difference between class methods and instance methods

2005-02-17 Thread Duncan Booth
Diez B. Roggisch wrote: > John wrote: >> ... hmm... bound methods get created each time you make >> a call to an instance method via an instance of the given class? > > No, they get created when you create an actual instance of an object. > So only at construction time. Creating them means taking

Re: difference between class methods and instance methods

2005-02-17 Thread Duncan Booth
John wrote: >> Note that it doesn't matter whether you call instance.foo(2) >> directly, or bind instance.foo to a variable first. Either will >> create a *new* bound method object, and the correct instance is used >> for the call. > > Za! What do you mean, "create a new bound method object"? I *

Re: difference between class methods and instance methods

2005-02-17 Thread Steven Bethard
John wrote: Steven Bethard wrote: John M. Gabriele wrote: class C(object): @classmethod def f(cls, *args): # do stuff Sorry -- I'm not as far along as you suspect. :) I've never yet seen this "@classmethod" syntax. I'm supposing that it's part of this so-called "new-style" class syn

Re: difference between class methods and instance methods

2005-02-17 Thread Diez B. Roggisch
> O. Unlike C++, where methods are not first class objects > and you only have *one* that gets shared by all instances. Exactly - so unlike in c++, where you have to do ugly hacks if e.g. a C-lib takes a callback and you want to pass an instance method, you can do that in python. It's real

Re: difference between class methods and instance methods

2005-02-17 Thread John
Diez B. Roggisch wrote: John wrote: ... hmm... bound methods get created each time you make a call to an instance method via an instance of the given class? No, they get created when you create an actual instance of an object. So only at construction time. Creating them means taking the unbound me

Re: difference between class methods and instance methods

2005-02-17 Thread Diez B. Roggisch
John wrote: > ... hmm... bound methods get created each time you make > a call to an instance method via an instance of the given class? No, they get created when you create an actual instance of an object. So only at construction time. Creating them means taking the unbound method and binding the

Re: difference between class methods and instance methods

2005-02-17 Thread John
Duncan Booth wrote: John M. Gabriele wrote: I've done some C++ and Java in the past, and have recently learned a fair amount of Python. One thing I still really don't get though is the difference between class methods and instance methods. I guess I'll try to narrow it down to

Re: difference between class methods and instance methods

2005-02-17 Thread John
Steven Bethard wrote: John M. Gabriele wrote: 1. Are all of my class's methods supposed to take 'self' as their first arg? If by "class's methods" you mean methods on which you called classmethod, then no, they shouldn't take a 'self' parameter, they should take a 'cls' parameter because the fir

Re: difference between class methods and instance methods

2005-02-17 Thread Duncan Booth
John M. Gabriele wrote: > I've done some C++ and Java in the past, and have recently learned > a fair amount of Python. One thing I still really don't get though > is the difference between class methods and instance methods. I > guess I'll try to narrow it down to a

Re: difference between class methods and instance methods

2005-02-16 Thread Steven Bethard
John M. Gabriele wrote: 1. Are all of my class's methods supposed to take 'self' as their first arg? If by "class's methods" you mean methods on which you called classmethod, then no, they shouldn't take a 'self' parameter, they should take a 'cls' parameter because the first argument to the func

difference between class methods and instance methods

2005-02-16 Thread John M. Gabriele
I've done some C++ and Java in the past, and have recently learned a fair amount of Python. One thing I still really don't get though is the difference between class methods and instance methods. I guess I'll try to narrow it down to a few specific questions, but any further input