python3反射

class Cmd:
# def __init__(self,name):
# self.name = name
def run(self):
while 1:
cmd = input('>>清输入命令>>').strip()
if hasattr(self,cmd):
func = getattr(self,cmd)
func()
def ls(self):
print('ls--->func')
def pwd(self):
print('pwd--->func')
def cat(self):
print('cat--->func')
cmd = Cmd()
cmd.run()

猜你喜欢

转载自www.cnblogs.com/sgwjj/p/9434141.html