指定用空格的参数运行一个python脚本 [英] Specifying arguments with spaces for running a python script
问题描述
如何运行与将包含空格的参数巨蟒?我使用的MacOS
例如,
>蟒蛇testProgram.py参数1参数2
,其中参数1是一个单独的参数?
,其中参数1是一个单独的参数。
块引用>您已经基本上回答了您的的的问题有,
参数1
确实是一个单独的参数。在换句话说,你需要引用它,像之一:
蟒蛇testProgram.py参数1参数2
这是不实际然而一个Python的问题,这取决于您正在使用运行Python脚本的外壳。
例如,用
庆典
,还有单,双引号,其中最重要的可能是各种扩展如$之间的差异首页
- 单引号变种不会做那些扩展How to run a python with arguments that would contain spaces? I am using MacOS
For example,
>python testProgram.py argument 1 argument 2
where "argument 1" is a single argument?
解决方案where "argument 1" is a single argument.
You've basically answered your own question there,
"argument 1"
is indeed a single argument.In other words, you need to quote it, something like one of:
python testProgram.py "argument 1" 'argument 2'
This isn't actually a Python issue however, it depends on the shell that you're using to run the Python script.
For example, with
bash
, there are differences between the single and double quotes, the most important of which is probably the various expansions like$HOME
- the single quoted variant does not do those expansions.这篇关于指定用空格的参数运行一个python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!