I found a way to reload the method of the class object at runtime, here is an example: First I define the class A, which lies on the file test.py.
class A:
def __init_(self):
pass
def Message(self):
print "1"
then I run the Python shell on linux and execute the following code:
>>> from test import A
>>> a = A()
>>> a.Message()
1
Now I vi test.py in the fly and change the "Message" method:
class A:
def __init_(self):
pass
def Message(self):
print "2"
but when I execute a.Message () in the Python shell, the result is always "1" and not "2"
How do I write code to make an "a.Message" object to execute updated code.
Many thanks!
chu
source
share