@工厂模式
class Beijing: def printreslut(self): print("ok") class Shanghai: def printreslut(self): print("shanghaiss") def get(name="beijing"): result=dict(beijing=Beijing,shanghai=Shanghai) return result[name]().printreslut() def send(name): if name=="beijing": print("ok") else: print("找不到你要的答案") if __name__=='__main__': send('shenzhen') try: get('shenzhen') except KeyError as e: print("找不到你要的答案")