I wrote this code:
import sys
import time
def change(str):
with open(file, 'w') as func:
if 'function' in sys.modules:
sys.modules.pop('function')
time.sleep(1)
func.write(str)
import function
function.add(1, 2)
It doesn't work well (it might use older version of the module\function) without time-break between
sys.modules.pop('function')
and
import function
I am looking for a more time efficient solution.