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()

posted @ 2018-08-06 23:08  alsoalso  阅读(204)  评论(0编辑  收藏  举报