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
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
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
> 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
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,
>
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
"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
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
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
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 *
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
> 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
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
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
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
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
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
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
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
19 matches
Mail list logo