FAQ
laotseu wrote:
(snip)
What you're doing here is 'replacing' an instance method with another
one (I guess in Python's parlance, we should say 'rebinding').

If what you're trying to do is just that (replacing an instance method),
do it the simplest way (the one that is not commented in your code).

Now if you want to 'replace' a method for all existing instances of a
class, I leave it up to some __class__ Guru !-)

Laotseu
Ok, I got it a few minutes later :

class Truc:
def test(self):
print "old test"

a = Truc()

def test2(self):
print "new test"

a.__class__.test = test2
a.test()
new test
Laotseu

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 6 of 8 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedJan 8, '03 at 8:34p
activeJan 10, '03 at 5:41a
posts8
users5
websitepython.org

People

Translate

site design / logo © 2022 Grokbase