I use ipython's reload and can automatically reload changes of code. But I found that if I add some new function to a class, the new function cannot be autoreloaded. Can anyone help to solve this? For example, I have a file main.py with code:
class A():
def f(self):
print "in f"
if __name__ == '__main__':
from main import *
a = A()
a.f()
When I use run -i main.py
in ipython, I can modify function f and use a.f()
in ipython shell to get new function running. But if I want to add a new function, for examle make the class definition as:
class A():
def f(self):
print "in f"
def g(self):
print "in g"
I cannot use a.g()
to run the new function, I will get:
AttributeError: A instance has no attribute 'g'
So, my question is how to autoreload new function in a class without re-run the whole code?