Christos TZOTZIOY Georgiou <[EMAIL PROTECTED]> wrote:
...
> >> > class Test:
> >> > def __init__(self, method):
> >> > self.m = new.instancemethod(method, self, Test)
...
> >self.m = method.__get__(self, Test)
>
> Almost true; not all builtin functions are descriptors though.
On Sat, 29 Jan 2005 10:24:27 +0100, rumours say that [EMAIL PROTECTED]
(Alex Martelli) might have written:
>Bill Mill <[EMAIL PROTECTED]> wrote:
> ...
>> > class Test:
>> > def __init__(self, method):
>> > self.m = new.instancemethod(method, self, Test)
>>
>> Beautiful! thank you ve
Bill Mill <[EMAIL PROTECTED]> wrote:
...
> > class Test:
> > def __init__(self, method):
> > self.m = new.instancemethod(method, self, Test)
>
> Beautiful! thank you very much. Looking into the "new" module in
> python 2.4, that's equivalent to:
>
> self.m = type(self.__init__)(met
On Fri, 28 Jan 2005 14:41:16 -0500, Terry Reedy <[EMAIL PROTECTED]> wrote:
>
> "Kamilche" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> >I see what you're attempting to do. However, your code, if it DID run,
> > would result in a method being added to the object, not the object's
"Kamilche" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>I see what you're attempting to do. However, your code, if it DID run,
> would result in a method being added to the object, not the object's
> class! Modify the class itself, not the object, as follows:
>
> |class Test:
> |
On Fri, 2005-01-28 at 11:17 -0500, Bill Mill wrote:
> Beautiful! thank you very much. Looking into the "new" module in
> python 2.4, that's equivalent to:
>
> self.m = type(self.__init__)(method, self, Test)
>
> I didn't know that you could call types to create another type.
Well, a type is ess
On Fri, 28 Jan 2005 11:59:50 -0500, Hans Nowak <[EMAIL PROTECTED]> wrote:
> Bill Mill wrote:
>
> > On Fri, 28 Jan 2005 11:09:16 -0500, Hans Nowak <[EMAIL PROTECTED]> wrote:
> >
> >
> >>To add m as a new method to the *class*, do this:
> >>
> >> >>> class test:
> >>... def __init__(self, meth
Bill Mill wrote:
On Fri, 28 Jan 2005 11:09:16 -0500, Hans Nowak <[EMAIL PROTECTED]> wrote:
>
To add m as a new method to the *class*, do this:
>>> class test:
... def __init__(self, method):
... self.__class__.method = method
... self.method()
...
>>> def m(self): print self
..
Kamilche,
On Fri, 28 Jan 2005 08:10:07 -0800 (PST), Kamilche
<[EMAIL PROTECTED]> wrote:
> I see what you're attempting to do. However, your code, if it DID run,
> would result in a method being added to the object, not the object's
> class! Modify the class itself, not the object, as follows:
>
Hans,
On Fri, 28 Jan 2005 11:09:16 -0500, Hans Nowak <[EMAIL PROTECTED]> wrote:
>
> m is a function. When you assign it to self.method, it's still a
> function. You don't create a new method that way; all you have is a new
> attribute called 'method' containing the function.
>
I figured as
Diez,
On Fri, 28 Jan 2005 16:57:37 +0100, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
> >
> > Why doesn't m get the implicit self parameter in the self.method()
> > call? How would I make it a proper member of the class, so that a
> > self.method() call would work with the above "m" function?
>
>
Bill Mill wrote:
Hello all,
I have a misunderstanding about dynamic class methods. I don't expect
this behavior:
In [2]: class test:
...: def __init__(self, method):
...: self.method = method
...: self.method()
...:
In [3]: def m(self): print self
...:
[...]
Type
I see what you're attempting to do. However, your code, if it DID run,
would result in a method being added to the object, not the object's
class! Modify the class itself, not the object, as follows:
|class Test:
|def __init__(self):
|self.method()
|
|def m(self):
|print self
|
|se
>
> Why doesn't m get the implicit self parameter in the self.method()
> call? How would I make it a proper member of the class, so that a
> self.method() call would work with the above "m" function?
Use new.instancemethod:
import new
class Test:
def __init__(self, method):
self.m =
On 28 Jan 2005 15:41:49 GMT, F. Petitjean <[EMAIL PROTECTED]> wrote:
> Le Fri, 28 Jan 2005 10:20:30 -0500, Bill Mill a écrit :
> > Hello all,
> >
> > I have a misunderstanding about dynamic class methods. I don't expect
> > this behavior:
> >
> > In [2]: class test:
> >...: def __init__(se
Le Fri, 28 Jan 2005 10:20:30 -0500, Bill Mill a écrit :
> Hello all,
>
> I have a misunderstanding about dynamic class methods. I don't expect
> this behavior:
>
> In [2]: class test:
>...: def __init__(self, method):
>...: self.method = method
>...: self.method()
Hello all,
I have a misunderstanding about dynamic class methods. I don't expect
this behavior:
In [2]: class test:
...: def __init__(self, method):
...: self.method = method
...: self.method()
...:
In [3]: def m(self): print self
...:
In [4]: test(m)
---
17 matches
Mail list logo