Newsgroups: comp.lang.python
From: Bruno Desthuilliers <bruno.42.desthuilli...@wtf.websiteburo.oops.com>
Date: Tue, 10 Jul 2007 16:46:25 +0200
Local: Tues, Jul 10 2007 10:46 am
Subject: Re: Dynamic method
Daniel Nogradi a écrit :
>> I have an issue I think Python could handle. But I do not have the This won't work as expected: >> knowledge >> to do it. >> Suppose I have a class 'myClass' and instance 'var'. There is function > How about this (note the first argument 'self' which is the instance > def method_for_instance( message ): > def method_for_class( self, message ): > class myClass( object ): > inst = myClass( ) > inst.method( 'hello' ) class Bidule(object): def greet(self, who): b = Bidule('Bruno') => The point is that Python functions are descriptor objects that, when b.greet = greet.__get__(b) Note that you don't need this to attach a function as method to a class HTH You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||