# -*- coding: UTF-8 -*- class Teacher: dic = {'查看学生信息':'show_student','查看讲师信息':'show_teacher'} def show_student(self): print("-------show_student") def show_teacher(self): print("-----------show_teacher") @classmethod def func(cls): print("*------1111111111") nezha = Teacher() for k in Teacher.dic: print(k) key = input("请输入需求:").strip() # cmd_str = cmd.split()[0] # if hasattr( self, "cmd_%s" % cmd_str): try: if hasattr(nezha,Teacher.dic[key]):#当没有的时候/没成功/待咨询 func = getattr(nezha, Teacher.dic[key]) func() except KeyError as e: print("输入错误",e)