且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

指定用空格的参数运行一个python脚本

更新时间:1970-01-01 07:58:48


  

,其中参数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.