python学习第十八天

import master

lst = ["akl", "obm"]
for i, item in enumerate(lst):
print(i,item)
while 1:
num = input('输入')
if num == '0':
master.akl()
if num == '1':
master.obm()
while 1:
s = input('输入你要测试的功能')

# 从模块中拿到你想测试的功能
if hasattr(master, s): # 判断是否有此功能
fn = getattr(master, s) # 从模块中货的这个方法
fn()
else:
print('没有这个方法')

print(getattr(master,"name"))
setattr(master, "name", 'Euan')
print(master.name)

class Car():
def __init__(self, color, pai, price):
self.color = color
self.pai = pai
self.price = price

def fly(self):
print('我的车会飞')

c = Car("黑色","兰博基尼",1000000000)
delattr(Car, "fly") # 可以操纵我们的类或者对象
c.fly()

setattr(Car,'fly', lambda self:print('我靠,我的车能飞'))
c.fly()

print(c.color)
setattr(c, 'color', '白色')
print(c.color)

print(getattr(c, 'pai'))
print(c.pai)

猜你喜欢

转载自www.cnblogs.com/EuanXu/p/9937462.html