---Python switch 代码处理方法!


Python是没有swithch语句, 这点还是对于我们这些整Java/C/Shell/... 人都是很不习惯, 你得这样才行!
#!/usr/bin/env python2
junk = "shoo2"

def shoo_fun1():
    print "hello ok1"

def shoo_fun2():
    print "hello ok2"

def shoo_fun3():
    print "hello ok2"

def default_fun():
    print "default"

sssDict = {
        'shoo1' :    shoo_fun1,
        'shoo2' :    shoo_fun2,
        'shoo3' :    shoo_fun3,
        "defautl" :  default_fun,
}

def processId(procID):
    sssDict[procID]()

processId(junk)

  从C/Java里面整这个字典功能也成, 成本高!
 
 

 

posted on 2021-02-06 23:44  linuxdog  阅读(107)  评论(0编辑  收藏  举报

导航