博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python switch-case语句的实现 -- 字典模拟实现
阅读量:5150 次
发布时间:2019-06-13

本文共 1683 字,大约阅读时间需要 5 分钟。

static voidprint_asru_status(int status, char *label){    char *msg = NULL;    switch (status) {    case 0:        msg = dgettext("FMD", "ok and in service");        break;    case FM_SUSPECT_DEGRADED:        msg = dgettext("FMD", "service degraded, "            "but associated components no longer faulty");        break;    case FM_SUSPECT_FAULTY | FM_SUSPECT_DEGRADED:        msg = dgettext("FMD", "faulted but still "            "providing degraded service");        break;    case FM_SUSPECT_FAULTY:        msg = dgettext("FMD", "faulted but still in service");        break;    case FM_SUSPECT_UNUSABLE:        msg = dgettext("FMD", "out of service, "            "but associated components no longer faulty");        break;    case FM_SUSPECT_FAULTY | FM_SUSPECT_UNUSABLE:        msg = dgettext("FMD", "faulted and taken out of service");        break;    default:        break;    }    if (msg) {        (void) printf("%s     %s\n", label, msg);    }}

以上代码是我做项目中遇到的一段代码,要求用Python语言实现,实现代码如下所示:

def print_asru_status(status, label):    dic = {0:"ok and in service",        FM_SUSPECT_DEGRADED:"service degraded, but associated components no longer faulty",        FM_SUSPECT_FAULTY | FM_SUSPECT_DEGRADED:"service degraded, but associated components no longer faulty",        FM_SUSPECT_FAULTY:"faulted but still in service",        FM_SUSPECT_UNUSABLE:"out of service, but associated components no longer faulty",        FM_SUSPECT_FAULTY | FM_SUSPECT_UNUSABLE:"faulted and taken out of service"}    if status not in dic:        msg = ""    else:        msg = dic[status]    if msg :        print(label,"     ", msg)

 

学习文章:

转载于:https://www.cnblogs.com/fendou-999/p/3534839.html

你可能感兴趣的文章
steps/train_sat.sh
查看>>
TLS 1.0协议
查看>>
java递归的几种用法
查看>>
转:Linux设备树(Device Tree)机制
查看>>
iOS 组件化
查看>>
python安装win32api pywin32 后出现 ImportError: DLL load failed
查看>>
(转)Tomcat 8 安装和配置、优化
查看>>
(转)Linxu磁盘体系知识介绍及磁盘介绍
查看>>
tkinter布局
查看>>
命令ord
查看>>
利用新浪微博来控制电脑
查看>>
洛谷 P3367 【模板】并查集
查看>>
方法Equals和操作符==的区别
查看>>
我的软件工程师之路,给需要的同学!
查看>>
快速模幂
查看>>
Unity3D_最简单的开始界面_结束界面
查看>>
TCP/IP五层模型
查看>>
Sharepoint 2013搜索服务配置总结(实战)
查看>>
10 个用来下载免费图标的网站
查看>>
noi.ac 第五场第六场
查看>>