irgendwas

parser.py

Aug 6th, 2016
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. #  @skate702 das ist genau das was du im stream mit noah versucht hast nur in python statt in scala
  2. ## tut mir leid dich belästigt zu haben wenn es dich nicht interessiert.
  3. def parse(cmd):
  4.  
  5.     if  cmd[:4] == "abc\/" and cmd[4] != " ":
  6.         print cmd
  7.         cmd2 = cmd[4:].split(" ")
  8.         #for i in cmd2: print i
  9.         print "preamble: " + cmd[:4]
  10.         print "command: " + cmd2[0]
  11.         print "args: " + str(cmd2[1:])
  12.            
  13.     elif cmd[:3] == "abc" and cmd[3] != " " and cmd[4] != " ":# <--just to be sure
  14.         cmd2 = cmd[3:].split(" ")
  15.         print cmd
  16.         #for i in cmd2: print i
  17.         print "preamble: " + cmd[:3]
  18.         print "command: " + cmd2[0]
  19.         print "args: " + str(cmd2[1:])
  20.        
  21.     else:
  22.         print "invalid command '%s', please check" %cmd # <--was first a ¨raise SyntaxError¨, which would stop the script completely
  23.  
  24. if __name__ == '__main__':
  25.     # test if it works
  26.     parse("abctime set 0")
  27.     parse("abc/time set 0")
  28.     parse("time set 0")
  29.     parse("/time set 0")
  30.     parse("abc time set 0")
  31.     parse("abc/ time set 0")
Advertisement
Add Comment
Please, Sign In to add comment