标签:att value ttl attr elf setattr class val sel
#setattr(object, name, values)给对象的属性赋值,若属性不存在,先创建再赋值
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
标签:att value ttl attr elf setattr class val sel
原文地址:https://www.cnblogs.com/xueli/p/9647468.html