1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
@工厂模式<br data - filtered = "filtered" > 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 ( "找不到你要的答案" ) |