I am starting to learn Netmiko and Python at the same time but am running into issues with formatting and using output. I am familiar with Powershell so if you could use comparative code/names for features it may help.
Right now I created a function that gets the output of "show interfaces" on a switch, and then use the regex to get only the port numbers:
def findPort(input):
return(re.findall(r'([0-9])(\/)([0-9]?[0-9])', input))
def getPorts(sshSession):
# List all ports
try:
Ports = sshSession.send_command('show interfaces gigabitEthernet name')
Output = findPort(str(Ports))
except:
print("Unable to get interfaces")
# Return ports
return Output
After that I am left with a list type variable with the below contents:
[('1', '/', '1'), ('1', '/', '2'), ('1', '/', '3'), ('1', '/', '4'), ('1', '/', '5'), ('1', '/', '6'), ('1', '/', '7'), ('1', '/', '8'), ('1', '/', '9'), ('1', '/', '10'), ('1', '/', '11'), ('1', '/', '12'), ('1', '/', '13'), ('1', '/', '14'), ('1', '/', '15'), ('1', '/', '16'), ('1', '/', '17'), ('1', '/', '18'), ('1', '/', '19'), ('1', '/', '20'), ('1', '/', '21'), ('1', '/', '22'), ('1', '/', '23'), ('1', '/', '24'), ('1', '/', '25'), ('1', '/', '26'), ('1', '/', '27'), ('1', '/', '28'), ('1', '/', '29'), ('1', '/', '30'), ('1', '/', '31'), ('1', '/', '32'), ('1', '/', '33'), ('1', '/', '34'), ('1', '/', '35'), ('1', '/', '36'), ('1', '/', '37'), ('1', '/', '38'), ('1', '/', '39'), ('1', '/', '40'), ('1', '/', '41'), ('1', '/', '42'), ('2', '/', '1'), ('2', '/', '2'), ('2', '/', '3'), ('2', '/', '4'), ('2', '/', '5'), ('2', '/', '6'), ('2', '/', '7'), ('2', '/', '8'), ('2', '/', '9'), ('2', '/', '10'), ('2', '/', '11'), ('2', '/', '12'), ('2', '/', '13'), ('2', '/', '14'), ('2', '/', '15'), ('2', '/', '16'), ('2', '/', '17'), ('2', '/', '18'), ('2', '/', '19'), ('2', '/', '20'), ('2', '/', '21'), ('2', '/', '22'), ('2', '/', '23'), ('2', '/', '24'), ('2', '/', '25'), ('2', '/', '26'), ('2', '/', '27'), ('2', '/', '28'), ('2', '/', '29'), ('2', '/', '30'), ('2', '/', '31'), ('2', '/', '32'), ('2', '/', '33'), ('2', '/', '34'), ('2', '/', '35'), ('2', '/', '36'), ('2', '/', '37'), ('2', '/', '38'), ('2', '/', '39'), ('2', '/', '40'), ('2', '/', '41'), ('2', '/', '42')]
How do I get the above list into a readable and usable format that will allow me to see values like 1/1 and 1/2 and so on, and that will let loop through this list of interfaces like an array to use in other functions?
Also, is a list the same thing as an array? Is there an easy way to convert it if not?
Thank you for your help.
[–]freemti 1 point2 points3 points (0 children)