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