Python – Kirk Byers Course Week 2 Part 4
This post will describe the exercises and solutions for week two of Kirk Byers Python for Network Engineers.
The final assignment in week 2 is the following:
IV. You have the following string from "show version" on a Cisco router cisco_ios = "Cisco IOS Software, C880 Software (C880DATA-UNIVERSALK9-M), Version 15.0(1)M4, RELEASE SOFTWARE (fc1)" Note, the string is a single line; there is no newline in the string. How would you process this string to retrieve only the IOS version: ios_version = "15.0(1)M4" Try to make it generic (i.e. assume that the IOS version can change). You can assume that the commas divide this string into four sections and that the string will always have 'Cisco IOS Software', 'Version', and 'RELEASE SOFTWARE' in it.
The first thing we want to do is to split the string into several parts and put them in a list. We were told that we could use the comma as a separator. We’ll print the list and show the type to show what is going on.
cisco_ios_list = cisco_ios.split(",") print(cisco_ios_list) print(type(cisco_ios_list))
This gives us the following output:
daniel@daniel-iperf3:~/python/Week2$ python3 ios_version.py ['Cisco IOS Software', ' C880 Software (C880DATA-UNIVERSALK9-M)', '\n Version 15.0(1)M4', Continue reading