终于知道了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/

为什么python中没有switch case语句的更多相关文章

  1. java中的Switch case语句

    java中的Switch case 语句 在Switch语句中有4个关键字:switch,case break,default. 在switch(变量),变量只能是整型或者字符型,程序先读出这个变量的 ...

  2. Python | 基础系列 · Python为什么没有switch/case语句?

    与我之前使用的所有语言都不同,Python没有switch/case语句.为了达到这种分支语句的效果,一般方法是使用字典映射: def numbers_to_strings(argument): sw ...

  3. Java中的Switch....case语句:

    一.格式: switch(表达式){ case 常量表达式1:  语句1;    case 常量表达式2:  语句2;    …     case 常量表达式n:  语句n;    default: ...

  4. C#中,switch case语句中多个值匹配一个代码块的写法

    switch (num) { case 1: Response.Write("1"); break; case 2: case 3: Response.Write("2| ...

  5. python技巧 switch case语句

    不同于C语言和SHELL,python中没有switch case语句,关于为什么没有,官方的解释是这样的 使用Python模拟实现的方法: def switch_if(fun, x, y):    ...

  6. python 中的"switch"用法

    转载:http://python.jobbole.com/82008/ 为什么Python中没有Switch/Case语句? 不同于我用过的其它编程语言,Python 没有 switch / case ...

  7. 逆向知识第九讲,switch case语句在汇编中表达的方式

    一丶Switch Case语句在汇编中的第一种表达方式 (引导性跳转表) 第一种表达方式生成条件: case 个数偏少,那么汇编中将会生成引导性的跳转表,会做出 if else的情况(类似,但还是能分 ...

  8. 为什么说在使用多条件判断时switch case语句比if语句效率高?

    在学习JavaScript中的if控制语句和switch控制语句的时候,提到了使用多条件判断时switch case语句比if语句效率高,但是身为小白的我并没有在代码中看出有什么不同.去度娘找了半个小 ...

  9. switch… case 语句的用法

    switch… case 语句的用法   public class Test7 { public static void main(String[] args) { int i=5; switch(i ...

随机推荐

  1. 物联网架构成长之路(28)-Docker练习之MQ中间件(Kafka)

    0. 前言 消息队列MQ,这个在一般的系统上都是会用到的一个中间件,我选择Kafka作为练手的一个中间件,Kafka依赖Zookeeper.Zookeeper安装上一篇博客已经介绍过了. 1. Kaf ...

  2. Delphi Format 格式化数字

    Format('x=%d', [12]); //'x=12' //最普通Format('x=%3d', [12]); //'x= 12' //指定宽度Format('x=%f', [12.0]); / ...

  3. users-and-groups-in-linux

    https://www.tecmint.com/compress-files-and-finding-files-in-linux/ https://www.tecmint.com/manage-us ...

  4. csv.writer写入文件有多余的空行

    在用csv.writer写入文件的时候发现中间有多余的空行. 最早打开方式只是‘w’,会出现多余的空行,网上建议使用binary形式‘wb’打开可以解决问题: with open('egg2.csv' ...

  5. const的位置问题

    来源:牛客网 下列哪两个是等同的 int b; 1.const int *a = &b; 2.const * int a = &b; 3.const int* const a = &a ...

  6. python输出有色记录

    一.第三方模块coloredlogs # Create a logger object. import logging logger = logging.getLogger('your-module' ...

  7. npm安装package.json中的模块依赖

    npm 一键安装 package.json里的依赖时有2种情况: 1.package.json不存在时 运行命令: npm init可自动创建package.json文件 2.package.json ...

  8. Python3输入输出

    Python两种输出值的方式: 表达式语句和 print() 函数. 第三种方式是使用文件对象的 write() 方法,标准输出文件可以用 sys.stdout 引用. 如果你希望输出的形式更加多样, ...

  9. java web (sevlet)请求之get,post,forward,redirect

    [参考]web请求之get,post,forward,redirect 1,form表单:可以采用post或者get请求,客户端主动跳转,url地址会改变为提交后的地址 2,forward:forwa ...

  10. Java8学习笔记(十一)--并发与非并发流下reduce比较

    BinaryOperator<Integer> operator = (l, r) -> l + r; BiFunction<Integer, Integer, Integer ...