在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有三个版本,可以查帮助看看。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-31
  • 2021-05-07
  • 2022-12-23
  • 2021-06-07
  • 2022-02-23
猜你喜欢
  • 2021-07-28
  • 2021-07-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案