zoukankan      html  css  js  c++  java
  • python swich case

    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")
  • 相关阅读:
    Ceph
    linux五天光速入门
    shell编程
    Docker&K8S&持续集成与容器管理--系列教程
    openstack系列
    爬虫快速入门
    python奇闻杂技
    机器学习
    数据分析
    量化分析
  • 原文地址:https://www.cnblogs.com/lshan/p/15342272.html
Copyright © 2011-2022 走看看