我用思科的设备和帕拉米科联系。我知道我可以用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?你知道吗
只需将cast
hostOutput = ssh.slave.recv(9999).decode('UTF-8')
键入str如下:或者
相关问题 更多 >
编程相关推荐