hofer a écrit :
Hi
hofer a écrit :
I have multiple objects all belonging to the same class
(which I didn't implement and whose code I don't want to modify)
Now I'd like to change one method for one object only (after it has
been created) without adding any overhead
to the call of the other ob
Hi
> > hofer a écrit :
> >> I have multiple objects all belonging to the same class
> >> (which I didn't implement and whose code I don't want to modify)
>
> >> Now I'd like to change one method for one object only (after it has
> >> been created) without adding any overhead
> >> to the call of t
On Oct 14, 7:50 pm, hofer <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have multiple objects all belonging to the same class
> (which I didn't implement and whose code I don't want to modify)
>
> Now I'd like to change one method for one object only (after it has
> been created) without adding any overh
Bruno Desthuilliers a écrit :
hofer a écrit :
Hi,
I have multiple objects all belonging to the same class
(which I didn't implement and whose code I don't want to modify)
Now I'd like to change one method for one object only (after it has
been created) without adding any overhead
to the call
George Sakkis a écrit :
(snip)
You're right of course; that's what you get with minimal testing ;)
Still it works with a small modification, binding self to b as default
argument:
b.foo = lambda self=b: "modified called on %s" % self
Ok, now with a real use case : use a named function instead
On Oct 14, 12:28 pm, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:
> George Sakkis a écrit :
>
>
>
> > On Oct 14, 1:50 pm, hofer <[EMAIL PROTECTED]> wrote:
> >> Hi,
>
> >> I have multiple objects all belonging to the same class
> >> (which I didn't implement and whose code I don't want to modify)
Christian Heimes a écrit :
Bruno Desthuilliers wrote:
If the class is a new-style one [1], it just requires invoking the
descriptor protocol by yourself to get a bound method, ie:
Another note about new style classes:
You can NOT overwrite most magic methods (__*__) on the instance. Most
magi
Bruno Desthuilliers wrote:
If the class is a new-style one [1], it just requires invoking the
descriptor protocol by yourself to get a bound method, ie:
Another note about new style classes:
You can NOT overwrite most magic methods (__*__) on the instance. Most
magic methods are only looked up
hofer a écrit :
Hi,
I have multiple objects all belonging to the same class
(which I didn't implement and whose code I don't want to modify)
Now I'd like to change one method for one object only (after it has
been created) without adding any overhead
to the call of the other object's methods.
On Oct 14, 11:20 am, George Sakkis <[EMAIL PROTECTED]> wrote:
> On Oct 14, 1:50 pm, hofer <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi,
>
> > I have multiple objects all belonging to the same class
> > (which I didn't implement and whose code I don't want to modify)
>
> > Now I'd like to change one met
George Sakkis a écrit :
On Oct 14, 1:50 pm, hofer <[EMAIL PROTECTED]> wrote:
Hi,
I have multiple objects all belonging to the same class
(which I didn't implement and whose code I don't want to modify)
Now I'd like to change one method for one object only (after it has
been created) without a
On Oct 14, 1:50 pm, hofer <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have multiple objects all belonging to the same class
> (which I didn't implement and whose code I don't want to modify)
>
> Now I'd like to change one method for one object only (after it has
> been created) without adding any overh
from functools import partial
class Point:
def __init__(self, x, y):
self.x, self.y = x, y
def show(self, n):
for i in range(n):
print "Point: (%s, %s)" % (self.x, self.y)
def new_method(obj, func):
def method(*args, **kw):
return func(obj, *args,
Hi,
I have multiple objects all belonging to the same class
(which I didn't implement and whose code I don't want to modify)
Now I'd like to change one method for one object only (after it has
been created) without adding any overhead
to the call of the other object's methods.
Is this possible
14 matches
Mail list logo