天天看点

python中动态加载模块和类方法实现

python中动态加载模块和类方法实现测试代码

文件名: mytest.py 具体代码如下:

注意:模块名,类名,方法名都是变量。

执行后输出如下:

> "d:\python27\python.exe"  "d:\test\src\mytest.py"

#module: <module 'mytest' from 'd:\test\src\mytest.py'>

#c: mytest.testclass

#obj: <mytest.testclass instance at 0x025f2aa8>

<mytest.testclass instance at 0x025f2aa8>

test

#mtd: <bound method testclass.echo of <mytest.testclass instance at 0x025f2aa8>>

#t: 3

1