Python3的动态加载模块简单实例
import os
import sys
import time
import myconfig
b = ['123']
a = os.path.abspath(myconfig.__file__)
print(a)
b[-1]=os.path.getmtime(a)
print(b)
while True:
a = os.path.abspath(myconfig.__file__)
mtime = os.path.getmtime(a)
if mtime != b[-1]:
del sys.modules['myconfig']
import myconfig
b[-1]=mtime
print(b)
print(myconfig.ip)
time.sleep(2)
感谢关注