Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python字符串参数解析_Python - Fatal编程技术网

Python字符串参数解析

Python字符串参数解析,python,Python,我正在使用python中的cmd类,它将我的所有参数作为一个大字符串传递给我。将此arg字符串标记为arg[]数组的最佳方法是什么 例如: args = 'arg arg1 "arg2 with quotes" arg4 arg5=1' result = split_args(args) 它看起来像: result = [ 'arg', 'arg1', 'arg2 with quotes', 'arg4', 'arg5=1' ]

我正在使用python中的cmd类,它将我的所有参数作为一个大字符串传递给我。将此arg字符串标记为arg[]数组的最佳方法是什么

例如:

args = 'arg arg1 "arg2 with quotes" arg4 arg5=1'
result = split_args(args)
它看起来像:

 result = [  
      'arg',
      'arg1',
      'arg2 with quotes',
      'arg4',
      'arg5=1'
]

完美的我不知道这个模块存在。
import shlex
shlex.split('arg arg1 "arg2 with quotes" arg4 arg5=1')