动态导入模块

module_t=__import__('m1.t')         #可以执行t,但拿到的是顶层的模块
print(module_t)
# module_t.t.test1()
# from m1.t import *
# from m1.t import test1,_test2
#
# test1()
# _test2()
import  importlib
m=importlib.import_module('m1.t')
print(m)                        #m拿到的就是t
m.test1()
m._test2()

 

posted @ 2019-03-26 16:42  wind_y  阅读(92)  评论(0编辑  收藏  举报