August 2019 • Reading time: 7 minutes
•In this post I will describe how to use python to execute raw queries on mysql databases. install the database First we need to install mysql or maria-db (a fork of mysql) either in unix or windows. if you have windows 10 you can install mysql on wsl (windows subsystem for linux).
Read More...July 2019 • Reading time: 4 minutes
•Many times we connect to a router or switch usually with netmiko and we want to parse the output of a command. TextFSM is a Python module for parsing semi-structured text into python tables. It uses templates that use regular expressions in order to parse the output. The good thing is that there are already hundreds of templates for many devices and commands.
Read More...June 2019 • Reading time: 3 minutes
•In this post I will present a python module that makes the parsing of cisco configuration files easy. The module is called CiscoConfParse Lets start by installing it pip install ciscoconfparse I will use the following cisco file which is taken from the documentation site, but I have added a few lines in the beginning
Read More...March 2019 • Reading time: 3 minutes
•In this post I will explain generators and generator expressions. Please read first the post on iterables and iterators. Generators are iterator objects that we can call to get the values one at a time. When a function has a yield statement, it returns a generator object. Then we can iterate through this, using a for loop or the next method.
Read More...March 2019 • Reading time: 4 minutes
•In this post I will explain the what is an iterable and what is the difference between Iterators and Iterables. An iterable is every object that can be iterated. In order for this to happen it must implement the __iter__ method, and the __iter__ method must return an iterator object. An iterator object is an object that implements the __next__ method.
Read More...March 2019 • Reading time: 2 minutes
•In this post I will explain the difference between the various scopes in python. By scope we mean that each variable, depending on where it is defined, has a certain area where it is valid and as a concequence has also a certain lifetime. Lets start with an example a=1 def func(): a=2 print(a) func() print(a) We have two variables called “a”, one is defined outside of anything and we say it has a module or global scope and the other one is defined inside a function and it has a local scope.
Read More...March 2019 • Reading time: 3 minutes
•In this post I will explain lambda expressions in python. Simply put, lambda expressions is another way to create a function in python. However this function has some restrictions. It does not have a name (that’s why they are also called anonymous), they can not have assignments they do not have a ‘return’ keyword and they can only be one line.
Read More...March 2019 • Reading time: 3 minutes
•In the previous post we saw how to unpack an iterable using the * operator and how to pass parameters to functions using the * operator. In this post I will show you how to pass parameters to functions using the ** operator and how to combine * and ** together.
Read More...March 2019 • Reading time: 3 minutes
•In this post I will explain what is unpacking and how it is used in Python. I will also explain how the “*” operator is used in unpacking. In another post I will explain the ** operator. Unpacking means that we assign an iterable to more primitive data types. For instance, lets say I have a list l1 = [1,2,3] and I want to assign a to 1, b to 2, c to 3.
Read More...March 2019 • Reading time: 4 minutes
•In this post I will analyze the difference between mutable and immutable objects in python and how this affects variables and functions. Lets start by defining two variables a = 10 b = a what is the value of b? If you guessed 10, then you are correct. b points to the same memory address as a, and thus the contents of this address is 10.
Read More...