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:

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.

This gives us the following output:

There was a “\n” inserted before “Version 15.0(1)M4” because we were using a multi line string. But we can take care of that later. Let’s print the list again with an index by using a For loop.

This gives us the list with the index:

We know that the version is stored at index 2. Let’s create a variable that stores the version and strip the “\n” from it. We will then print the variable.

This gives us the version without the “\n”.

We now have the version but we want to extract the version number from this. We can use “split()” and tell it to split the string into two parts, one with “Version ” and the other with whatever follows that string. Note the space that was inserted after the string. We then print the IOS version.

This should give us the version number:

We got the IOS version by splitting the string stored in “ios_version” into two parts where the first part at index 0 is “Version ” and the second part at index 1 is the version number.

I hope this has been informative and check the code at Github if you want to. See you next time!

Python – Kirk Byers Course Week 2 Part 4

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: