两种动态载入修改后的python模块的方法

时间:2023-03-09 18:36:29
两种动态载入修改后的python模块的方法

方案一:循环导入/删除模块

a.py

import sys, time

while True:
from b import test
test()
del sys.modules(b)
time.sleep(1)

b.py

def test():
print "something"

方案二:reload模块

a.py

import time
import b while True:
b.test()
reload(b)
time.sleep(1)

b.py

def test():
print "something"