简单Python超编程

首先需要安装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人朋友们可以改变几个数字,观察运行结果

评论

暂无评论