指定用空格的参数运行一个python脚本 [英] Specifying arguments with spaces for running a python script

查看:293
本文介绍了指定用空格的参数运行一个python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何运行与将包含空格的参数巨蟒?我使用的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆