Following up on this question regarding reloading a module, how do I reload a specific function from a changed module?
pseudo-code:
from foo import b
If you are the author of foo.py, you can write:
with open('bar.py') as f: bar_code=compile(f.read(),'bar.py','exec')
def bar(a,b):
exec(bar_code)
def reload_bar():
global bar_code
with open('bar.py') as f: bar_code=compile(f.read(),'bar.py','exec')
Then, in your pseudocode, reload if bar.py has changed. This approach is especially nice when bar lives in the same module as the code that wants to hot-reload it rather than the OP's case where it lives in a different module.