首先需要安装import_string
指令行输入 pip install import_string 然后创建源代码文件appentry.py import import_string;if name == "main":
moduletest = import_string("mdtest")
result = moduletest.testfunc0(2,4)
if result == 1 :
print("Test Module Output : OK")
else :
print("Test Module Output : Failed")
moduleplugin = import_string("mdplugin")
result = moduleplugin.pluginfunc0(5)
print(result)
源代码结束
创建源代码文件mdplugin.py
def pluginfunc0(x):
return x ** 2
源代码结束
创建源代码文件mdtest.py
import import_string;def testfunc0(x,y):
moduleplugin = import_string("mdplugin")
result1 = moduleplugin.pluginfunc0(x)
result = 0
if result1 == y:
print("Test OK!")
result = 1
else :
print("Test Failed")
result = 0
return result
源代码结束
所有源代码文件都必须在同一个文件夹内
运行appentry.py
Test OK!Test Module Output : OK
25
IT人朋友们可以改变几个数字,观察运行结果