Welcome to the next pikoTutorial ! If you haven’t read the previous pikoTutorial on setting up a Python project with CMake, you may want to check it out first because in today’s article I’ll be using the setup we’ve done there: However, I will extend it with the test directories…
Python
How to derive from an enum in Python?
Welcome to the next pikoTutorial ! Recently I’m experimenting with different ways of error handling in Python and I stumbled upon a use case in which it would be very helpful to create an enum by deriving from a different enum. Use case Let’s say we design an interface for…
Setting up a Python project with CMake
Welcome to the next pikoTutorial ! CMake is often associated only with C/C++ and occupies a high place in the ranking of the most hated tools. Today, I want to show an unusual, but interesting use case – setting up and running Python applications with CMake and its underlying generators.…
UDP multicasting with Python
Welcome to the next pikoTutorial! The minimal receiver Note for beginners: do not remove line 14 from the receiver implementation! Without the ability to re-use the same address, you will not be able to run more than 1 multicast receiver and you’ll end up with a simple UDP client/server setup.…
TCP client/server with Python
Welcome to the next pikoTutorial ! The minimal TCP server A TCP server listens for incoming connections on a specified port and communicates with clients over that connection. The minimal TCP client A TCP client establishes a connection with a server, sends data, and receives responses. Bidirectional communication You can…
Python lru_cache explained
Welcome to the next pikoTutorial! Imagine you’re developing an application that fetches data from external API. For example, a weather app might request current weather conditions for a list of cities and then display them. While the data is updated periodically, repeatedly querying the API with the same city is…
Python reduce explained
Welcome to the next pikoTutorial! The reduce function is a powerful tool placed in the functools module that facilitates the cumulative application of a function to the items of an iterable (from left to right), to reduce them to a single value. Initially introduced in Python 2, later moved to…
5 Python good practices which make life easier
Welcome to the next pikoTutorial! Print exceptions traceback after catching them Consider the following example code that raises an exception: When we run it, we see the following output: The traceback provides detailed information, including where the error occurred, the exception type, and the error message. However, the downside is…
UDP client/server with Python
Unlike TCP (Transmission Control Protocol), UDP is connectionless, meaning it does not require a handshake process to establish a connection before data transmission.
Yield in Python – state machines, coroutines and more
yield is a well known keyword in Python which allows to optimize the code by generating data streams on the fly instead of generating the same data all at once.
How to test method call order with unittest in Python?
Welcome to the next pikoTutorial! Sometimes when writing unit test it is necessary to check not only if certain function has been called, but also the order in which functions have been called. To do that with unittest in Python, use the following code: If you change the order of…
Key derivation function with Python
Below you can find the extended example of how to use PBKDF2HMAC key derivation function in Python.
Symmetric data encryption with Python
One of the simplest ways to perform symmetric encryption in Python is to use Fernet algorithm from cryptography module. Let’s see how to use it.
Hacking Python functions by changing their source code
Changing function by modifying its implementation manually is obvious, but can we change the implementation of the function at runtime of the application?