AttributeError:“unicode”对象没有“readlines”属性

2024-09-30 04:39:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我用思科的设备和帕拉米科联系。我知道我可以用netmiko代替paramiko,但这不是我现在的问题重点。无论如何,在执行命令“show run | I hostname\n”并将输出保存到变量“hostOutput”之前,我希望在行中搜索单词“hostname”。找到单词后,我想把整行打印出来。你知道吗

def devInfo(): 
print ('')
print ('[3] Collecting device informations...')
print ('')
ssh.slave.send('show run | i hostname\n')
time.sleep(1)
hostOutput = ssh.slave.recv(9999).decode('UTF-8')
lines = hostOutput.readlines()
for line in lines:
   if re.search(r'hostname', line):
     print line
     break
devInfo()

但是我得到了异常AttributeError:'unicode'对象没有属性'readlines'。。。我做错什么了?如何修复unicode,使其成为str?你知道吗


Tags: runshowlineunicode单词sshhostnameslave

热门问题