开发者

Python String Argument Parsing

I am working with the cmd class in python and it passes me all of my arguments as one big string. What is the best way to tokenize this arg string into an array of args[].

Example:

args = 'arg arg1 "arg2 with quotes" arg4 arg5=1'
result = split_args(args)

And it would look like:

 result = [  
      'arg',
      '开发者_如何学运维arg1',
      'arg2 with quotes',
      'arg4',
      'arg5=1'
]


import shlex
shlex.split('arg arg1 "arg2 with quotes" arg4 arg5=1')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜