Logging in Python

Posted on Sun 07 July 2024 in Python • Tagged with python, backend

Having reliable, detailed but searchable logs is an essential part of any application, especially of long-running services that need to be debugged and monitored for uptime and stability. As one of the oldest modules in the Python standard library, the logging module provides a very powerful set of tools for …


Continue reading

Object creation patterns in Python: Static factory methods

Posted on Tue 21 May 2024 in Python • Tagged with python, object-oriented-programming, design-patterns

The basic way to create and initialize an object in Python is using the default constructor, defined as the __init__() method:

class MyClass:
    def __init__(self, x: float) -> None:
        self.x: float = x
        print(f"created an object with x = {x}")


obj = MyClass(5)

Usually, initial values of instance variables …


Continue reading

for loops in Python are a bit weird

Posted on Sun 11 February 2024 in Python • Tagged with python, javascript

A quiz:

What does the following JavaScript code print and why?

for (let i = 0; i < 3; i++) {
  console.log(i);
  i -= 3
}

What does the following Python code print and why?

for i in range(3):
    print(i)
    i -= 3