setatt

r给对象的属性赋值,若属性不存在,先创建再赋值

用法

setattr(object, name, values)

  • object -- 对象。
  • name -- 字符串,对象属性。
  • value -- 属性值。

 

def testadd():
    print 'testasdd'


class Test(): name='tttli' def testrun(self): print 'testrun' #增加Test类的参数 setattr(Test,"age","19") #增加Test类的函数 setattr(Test,"myadd",testadd())
test
=Test() test.myadd #testasdd print test.age #19

 

相关文章:

  • 2021-11-07
  • 2021-06-14
  • 2022-12-23
  • 2021-12-24
  • 2021-06-07
  • 2021-08-02
  • 2021-09-21
  • 2021-06-17
猜你喜欢
  • 2021-09-11
  • 2021-12-05
  • 2022-03-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案