终奌站:
python test.py blah='blah'
在test.py中
print sys.argv
['test.py', 'blah=blah'] <------------ 
怎么能保持它的''或者
有没有办法知道一个arg是用""还是""包裹?
Mar*_*ers 12
您的shell在调用Python之前删除了引号.这不是Python可以控制的.
添加更多报价:
python test.py "blah='blah'"
也可以放在参数的任何位置:
python test.py blah="'blah'"
或者你可以使用反斜杠转义:
python test.py blah=\'blah\'
保护它们.这取决于您用于运行命令的确切shell.
演示bash:
$ cat test.py 
import sys
print sys.argv
$ python test.py blah='blah'
['test.py', 'blah=blah']
$ python test.py "blah='blah'"
['test.py', "blah='blah'"]
$ python test.py blah="'blah'"
['test.py', "blah='blah'"]
$ python test.py blah=\'blah\'
['test.py', "blah='blah'"]
| 归档时间: | 
 | 
| 查看次数: | 3335 次 | 
| 最近记录: |