【发布时间】:2012-06-03 19:13:44
【问题描述】:
运行 python 脚本时如何读取带空格的参数?
更新:
看来我的问题是我正在通过 shell 脚本调用 python 脚本:
这行得通:
> python script.py firstParam file\ with\ spaces.txt
# or
> python script.py firstParam "file with spaces.txt"
# script.py
import sys
print sys.argv
但是,不是当我通过脚本运行它时:
myscript.sh:
#!/bin/sh
python $@
打印:['firstParam', 'file', 'with', 'spaces.txt']
但我想要的是: ['firstParam', '带空格的文件.txt']
【问题讨论】: