基于"在Python中用空格分割字符串",它使用shlex.split智能地分割带引号的字符串,我将有兴趣听到非显而易见的标准库函数解决的其他常见任务.
如果这变成了本周的模块,那也没关系.
如何将字符串拆分-s -k "test_a or test_b" -m "not unstable" --results=/tmp/test-results --log-cli-level=INFO为
['-s', '-k', 'test_a or test_b', '-m', 'not unstable', '--results=/tmp/test-results', '--log-cli-level=INFO']
Run Code Online (Sandbox Code Playgroud) python ×2