更新时间:2023-08-25 23:05:04
您可以查看cmd库: http://docs.python.org/library/cmd.html
You can take a look at the cmd lib: http://docs.python.org/library/cmd.html
如果要自己解析,可以使用split
标记用户输入,并基于标记执行命令,如下所示:
If you want to parse by yourself, you can use split
to tokenize the user input, and execute your commands based on the tokens, sort of like this:
try:
while True:
input = raw_input('> ')
tokens = input.split()
command = tokens[0]
args = tokens[1:]
if command == 'init':
# perform init command
elif command == 'blah':
# perform other command
except KeyboardInterrupt:
pass