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)
posted @ 2017-03-02 17:51  Dus  阅读(1484)  评论(0编辑  收藏  举报