python中根据类名生成类的实例

在python中和.net一样可以根据类名来动态生成类的实例,但是比.net更方便,下面的例子使用python2.4的idle的IDE环境,
.py文件代码如下:
class Employee
    def __init__(self,name,age,address): 
        print 'name   :',name 
        print 'age    :',age 
        print 'address:',address 
    def test(self): 
        print 'test'

obj = apply(Employee,('jack',18,'china'))
obj.test()

按F5运行,在shell窗口看到输出结果:
>>> ================================ RESTART ================================
>>>
name   : jack
age      : 18
address: china
test
>>>

是很简单吧。
apply有三个版本,可以查帮助看看。

原文地址:https://www.cnblogs.com/dahuzizyd/p/111737.html