Posts categorized under: Python

How to debug with logging

Many developers often use print statements for debugging their code. Print statements are a good way to trace and troubleshoot potential problems, but they are not great when working on collaborative projects. Prints are also problematic in multi-threaded programs. You have to remove your print statements before shipping your code ...

Concatenation of strings in Python

Most Python books or blog posts, teach us that concatenating strings using the + sign is a bad idea. This is true: using + or =+ is a really bad idea. In Python, strings are immutable. This means that every time your assign a new value or you want to increase the size ...

Managing records in python

A simple way to access data from a file or from a database is to read each line or row, then assign each value to a list or a tuple. The data that has been read can then be accessed by its position in the list.

Optimizing your code with __slots__

Python like many other dynamic programming languages can be extended. Objects and definitions can be modified at runtime. This gives the developer great power but this power comes at a price.

During the execution two instances of the same object can have different properties. This is why python accesses these ...