终于知道了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. js 性能优化利器:prepack

    1. js 性能优化 js 本身是没有像 python 一样的预编译功能,更没有像 java 一样的编译功能,所以,这里所说的 js 代码预编译 只是通过工具实现的类似功能而已. 这就要提到 prep ...

  2. SQL获取当前时间月份为两位数

    --获取当前时间月份为两位数 )),) --获取当前时间上月月份为两位数 , )),)

  3. U-BOOT2016.05 配置内存大小

    bootargs 里面有一个 mem 的参数,将这个配置 512M 便是将内存配置为 512M

  4. 怎样通过 DLNA 将电脑上的媒体投射到智能电视上

    DLNA 是一种网络设备间共享媒体的解决方案.从 Windows 7 开始就支持 DLNA,现在一些国产智能电视也已经支持 DLNA 了,这就为我们在电脑和电视之间方便地共享多媒体提供了条件. 工具/ ...

  5. hdoj:2048

    #include <iostream> using namespace std; ]; ]; int main() { int C; a[] = ; a[] = ; b[] = ; b[] ...

  6. getCanonicalFile与getAbsoluteFile区别

    package test; import java.io.File; import java.io.IOException; public class TestFilePath { public st ...

  7. Android gradle 配置

    gradle https://www.cnblogs.com/qianxudetianxia/p/4948499.html flavor https://blog.csdn.net/user11223 ...

  8. 使用Pip在离线环境安装Python依赖库

    一.安装多个包 1.有网的服务器 1.生成requirement.txt文件 pip freeze >/tmp/wheel_pip/requirements.txt 这个命令会把当前环境下面的p ...

  9. 【Postgres】空间数据库创建

    1.数据库创建问题-Navicat-ERROR: source database "template1" is being accessed by other users 2.解决 ...

  10. miniprogrampatch 提供 watch 和 computed 特性

    推荐一个小程序补丁 github:miniprogrampatch,为你的 Page 和 Component 增加 watch 和 computed 特性. 安装 通过 npm 安装:npm inst ...