Python String Tips for Network Automation
Автор: Ferds Tech Channel
Загружено: 2024-11-05
Просмотров: 46
Описание:
In this video I talk about a few Python string tips/techniques you can use for string manipulation and inspection. Below is the code I used in the video:
http://routeviews.org/
from netmiko import ConnectHandler
Define the Cisco device
cisco_device = {
"device_type": "cisco_ios_telnet",
"host": "route-views.routeviews.org",
"username": "rviews",
}
Establish connection
connection = ConnectHandler(**cisco_device)
hostname = connection.find_prompt().strip("#")
output = connection.send_command("show clock")
Using repr() to show raw string with escape sequences
print(repr(output))
Using r"..." to make file paths easier to manage
file_path = r"C:\Users\user\Desktop\ftc\Topics\Python\netmiko\device_output.txt"
with open(file_path, "w") as file:
file.write(hostname + "\n")
file.write(output + "\n")
Using len() to measure string length
print("Hostname length:", len(hostname))
print("Clock output length:", len(output))
Using Escape Sequences to improve output readability
print(f"Hostname: {hostname}\nClock Info:\n{output}\n")
Disconnect the connection
connection.disconnect()
#pythonforbeginners #coding #networkautomation
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: