为什么python中没有switch case语句

终于知道了python中映射的设计哲学.

我自己写的code :

 1 class order_status_switcher(object):
 2     def get_order_status(self,argument= checkUserAppBookDateResult(appkey,"",1,token)):
 3         #dispatch method
 4         method_name = 'number_'+str(argument.get("data").get("orderResultModel").get("orderStatus"))
 5         # Get the method from 'self'. Default to a lambda.
 6         method = getattr(self,method_name,lambda :"nothing")
 7         # Call the method as we return it
 8         return method()
 9     # get orderStatus=1,orderStatusDesc="已受理"
10     def number_1(self):
11         return "已受理"
12     #get orderStatus=2,orderStatusDesc="已接单"
13     def number_2(self):
14         return "已接单"
15     #get orderStatus=3,orderStatusDesc="已出发"
16     def number_3(self):
17         return "已出发"
18     #get orderStatus=4,orderStatusDesc="服务中"
19     def number_4(self):
20         return "服务中"

看完这段代码你就理解了吧.

原文地址:

https://www.pydanny.com/why-doesnt-python-have-switch-case.html

翻译:

http://python.jobbole.com/82008/

posted @ 2017-07-31 21:04  Eillot  阅读(904)  评论(0)    收藏  举报