面向对象编程-类的属性-getattr

vim modify_attri.py

#!/usr/bin/env python

class person:

  deftell(self,name):

    print 'hi myname is',name

 

class student(person):

  def study(self):

    print 'I amstudying py right now'

 

 

s=student()

s.tell('rsc')

s.study()

 

s1=student()

s1.tell('gmy')

s1.study()

s1.age=30

print s1.age

 

p=student()

vars=['tell','study']

v1=vars[0]

getattr(p,v1)('oldboy')

 

结果

[root@node110 class]# python modify_attri.py

hi my name is rsc

I am studying py right now

hi my name is gmy

I am studying py right now

30

hi my name is oldboy

 

 

分割线
感谢打赏
江西数库信息技术有限公司
YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS