简体   繁体   中英

iPython: How can I import a newly added function from module?

I do a lot of interactive work in iPython. Currently, I'm working with Jupyter QtConsole. Suppose I start with this:

from myFuncs import func1

Then I go out to myFuncs.py and add a new function, func2. If I try this:

from myFuncs import func2

It doesn't see it. Presumably myFuncs is somehow cached. I have read about reload , but it seems to only work with entire modules, not cherry picked functions. autoreload also seems ineffective here. Is there a way around, short of restarting the kernel?

Incidentally, ipython within Spyder is fine with files changing while interacting. It is also unusably slow, so maybe related?

As @jss367 mentioned here , you can achieve this with importlib and sys modules:

import importlib
import sys
importlib.reload(sys.modules['myFuncs'])
from myFuncs import func2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM