![](/img/trans.png)
[英]How would you go about printing a value based the input value and the input value location in Python?
[英]How would I go about printing a line that reads “ input errors detected” based on the output of the sent command?
我是python的新手,我正在编写一个python脚本,它将命令发送到Cisco交换机并返回特定的行。 我遇到困难的部分是如何根据命令的输出打印一条表示“检测到输入错误”的行。 例如,如果一行中有0个输入错误,它什么都不做,但如果该行的值大于零输入错误,它将打印“检测到输入错误”? 谢谢。
命令(ssh_session.send_command(“sh interfaces | in up | CRC”))返回如下行“0输入错误,0 CRC,0帧,0溢出,忽略0”
for device in (cisco1, cisco2):
ssh_session = netmiko.ConnectHandler(**device)
print("+++++ {0} +++++".format(device["ip"]))
output = (ssh_session.send_command("sh interfaces | in up|CRC"))
for line in output.splitlines():
if "input errors" in line:
print(line)
ssh_session.disconnect()
您需要做的是解析输出消息。 这是一种方式(可能有更好的方法):
这假设输出的结构是你上面粘贴的 - 可能有很多边缘情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.