Python for Network Engineers

Decorators With Parameters

By George El. • March 2019 • Reading time: 2 minutes

In this post we will continue on decorators, and I will show you how we can pass parameters to decorators. Please read the previous post Decorators in Python if you are not familiar with decorators. In the previous post we saw this example. def outerf(fn): from datetime import datetime def innerf(*args, **kwargs): print (datetime.

Decorators in Python

By George El. • March 2019 • Reading time: 2 minutes

In this post I will explain decorators in python. This is a rather advanced topic. You should first read about [First class functions and Closures] (/posts/python-advanced/first_class_functions_in_python_and_closures/), in previous post. As we saw in previous post, functions can accept functions as arguments and return functions. Lets see an example. def outerf(fn): from datetime import datetime def innerf(*args, **kwargs): print (datetime.

First Class Functions in Python and Closures

By George El. • March 2019 • Reading time: 2 minutes

In this post I will explain first class functions. According to wikipedia: “In computer science, a programming language is said to have first-class functions if it treats functions as first-class citizens. This means the language supports passing functions as arguments to other functions, returning them as the values from other functions, and assigning them to variables or storing them in data structures.