
终于知道了python中映射的设计哲学.
我自己写的code :
class order_status_switcher(object):
def get_order_status(self,argument= checkUserAppBookDateResult(appkey,"",1,token)):
#dispatch method
method_name = 'number_'+str(argument.get("data").get("orderResultModel").get("orderStatus"))
# Get the method from 'self'. Default to a lambda.
method = getattr(self,method_name,lambda :"nothing")
# Call the method as we return it
return method()
# get orderStatus=1,orderStatusDesc="已受理"
def number_1(self):
return "已受理"
#get orderStatus=2,orderStatusDesc="已接单"
def number_2(self):
return "已接单"
#get orderStatus=3,orderStatusDesc="已出发"
def number_3(self):
return "已出发"
#get orderStatus=4,orderStatusDesc="服务中"
def number_4(self):
return "服务中"
看完这段代码你就理解了吧.
原文地址:
https://www.pydanny.com/why-doesnt-python-have-switch-case.html
翻译:
http://python.jobbole.com/82008/