【发布时间】:2014-09-02 12:50:44
【问题描述】:
我有一个可通过 Apache 访问的 php 脚本,它调用 python 脚本来 cat /etc/redhat-release 在两台服务器上并返回结果并将它们分配为两个不同的变量。然后我将这两个变量打印到屏幕上。问题是它将它们打印在屏幕上的同一行:['Red Hat Enterprise Linux Server release 6.5 (Santiago)\n', 'Red Hat Enterprise Linux Server release 6.2 (Santiago)\n']
我尝试在 to 之间插入 \n 或“\n”,但出现错误: SyntaxError: 无效语法
File "/var/www/html/php/check_version.py", line 35
print first + \n second
^
SyntaxError: unexpected character after line continuation character
如果我将它们打印在两行上,它只会给我最后一个变量。例如:
print first
print second ( I only get this result on the screen )
我错过了什么?
这是我的脚本:
#!/usr/bin/python
import paramiko, os, string, threading
import getpass
import socket
import sys
firsthost = '192.168.1.4'
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(firsthost, username='user', password='password')
stdin, stdout, stderr = ssh.exec_command('cat /etc/redhat-release')
first = stdout.readlines()
secondhost = '192.168.1.5'
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(secondhost, username='user', password='password')
stdin, stdout, stderr = ssh.exec_command('cat /etc/redhat-release')
second = stdout.readlines()
print first + second
ssh.close()
【问题讨论】:
-
添加了python-2.6标签,移除了变量标签
标签: php python linux newline python-2.6