PyCon 2011
本作品采用知识共享署名-非商业性使用-相同方式共享 3.0 Unported许可协议进行许可。允许非商业转载,但应注明作者及出处。作者:liuyuan_jq
2011-03-30
完整源码
#!/usr/bin/env python# encoding: utf-8# shlex_split.py"""Splitting a command line into arguments."""import shlexfor cmd in [ r'''ls "hidden stdlib" "\"already quoted\"" "with ' embedded"''',# subprocess"""ls 'hidden stdlib' '"already quoted"' 'with '"'"' embedded'""", # pipes]:print cmdprint cmd.split(' ')print shlex.split(cmd)print
运行结果
''ls "hidden stdlib" "\"already quoted\"" "with ' embedded"["''ls", '"hidden', 'stdlib"', '"\\"already', 'quoted\\""', '"with', "'", 'embedded"']['ls', 'hidden stdlib', '"already quoted"', "with ' embedded"]ls 'hidden stdlib' '"already quoted"' 'with '"'"' embedded'['ls', "'hidden", "stdlib'", '\'"already', 'quoted"\'', "'with", '\'"\'"\'', "embedded'"]['ls', 'hidden stdlib', '"already quoted"', "with ' embedded"]
页:
[1]