Jython import or reload dynamically
jython, python
Solution
How about just unloading all modules so they are reloaded on the next import:
import sys
sys.modules.clear()
Problem
I have to code something in Jython, for CCPS (programm using jython as scripting interface). However Jython does not update the submodules if I change them in an editor, unless I restart the programm (startup time is prohibitive). SO testing and adjusting is relatively slow. I have googled and found a post indicating, that one should import or reload the submodules. The basic outline thus is: ``` def loader(module, part=None): if not module in sys.modules : if part == None: exec("import "+module) else: exec("from %s import %s" % (module, part)) else : exec("reload "+module) ``` however I have an issue with this, the module is loaded locally, meaning i can access the module within the `loader()` function, but not in my main code. Two questions: What is the right way to test something with submodules in Jython without restarting Jython after each submodule change? Is there a way to generate globals dynamically so I can import into the global namespace? (e.g. `exec("global %(mod)s = %(mod)s" % ({'mod':module}))`