Advertisement
mosaid

python switch

Oct 17th, 2020 (edited)
2,067
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. # define your functions
  2. # then
  3. def myfuncSwitch(arg):
  4.     cmd = arg[1]
  5.     switcher = {
  6.         "create": createDB,
  7.         "addpass": addPass,
  8.         "all": getAll,
  9.         "authenticate": authenticate,
  10.         "getlistname": getPlayListName,
  11.         "getlists": getPlayLists,
  12.         "get": get,
  13.         "set": set,
  14.         "add": addFile,
  15.         "addtitle": addTitle,
  16.         "addtolist": addFileToList,
  17.         "remove": removeFile,
  18.         "getnfiles": getCount,
  19.         "search": search,
  20.         "addlist": addList,
  21.         "delete": deleteFile,
  22.         "isremoved": isRemoved,
  23.     }
  24.     func = switcher.get(cmd)
  25.     func(*arg[2:])
  26.  
  27.  
  28. def main():
  29.     myfuncSwitch(sys.argv)
  30.  
  31.  
  32. if __name__ == "__main__":
  33.     main()
  34.  
  35.  
  36. # call your script like : $ myscript.py delete arg1 arg2 ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement