Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python脚本中的bash命令中使用三个不同的引号_Python_Bash_Ssh - Fatal编程技术网

在Python脚本中的bash命令中使用三个不同的引号

在Python脚本中的bash命令中使用三个不同的引号,python,bash,ssh,Python,Bash,Ssh,我想在python脚本中使用三个不同的引号,因为我想在不同的计算机上执行两行python命令。例如: import commands command = "ssh someothercomputer 'python -c `import psutil; print psutil.cpu_percent()`'" output = commands.getstatusoutput(command)[1] 但是,反勾号不能识别为引号。错误如下: "Badly placed ()'s.\nArgum

我想在python脚本中使用三个不同的引号,因为我想在不同的计算机上执行两行python命令。例如:

import commands
command = "ssh someothercomputer 'python -c `import psutil; print psutil.cpu_percent()`'"
output = commands.getstatusoutput(command)[1]
但是,反勾号不能识别为引号。错误如下:

"Badly placed ()'s.\nArgument expected for the -c option\nusage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...\nTry `python -h' for more information."

如何使其工作?

不使用反勾号,您可以将内部引号转义,使其位于
命令中。像这样:

command =  "ssh someothercomputer 'python -c \"import psutil; print psutil.cpu_percent()\"'"
使用
命令执行此命令
产生所需的输出(另一台计算机上的当前cpu百分比)