首页 > 编程语言 > 详细

python swich case

时间:2022-05-27 20:06:55      阅读:20      评论:0      收藏:0      [点我收藏+]

python swich case,使用字典实现,原理,闭包

# swich case
def handler_result(op, ns, value):
    todos = {
        "i": insert,
        "u": update,
        "d": delete
    }
    method = todos.get(op, other)
    if method:
        method(ns, value)

def other(ns, value):
    print("ns:"+ns+" v:"+value)
    print("other")
def update(ns, value):
    print("ns:"+ns+" v:"+value)
    print("update")
def insert(ns, value):
    print("ns:"+ns+" v:"+value)
    print("insert")
def delete(ns, value):
    print("ns:"+ns+" v:"+value)
    print("delete")

if __name__ == __main__:
    # start_kafkaListener()
    handler_result("d", "sea.test", "xxxdel")
    handler_result("i", "sea.test", "xxxinsert")
    handler_result("u", "sea.test", "xxxupdate")

 

python swich case

原文:https://www.cnblogs.com/lshan/p/15342272.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!