Python Programming - Beginner Level

Introduction to a Handy Python Package - structlog

When starting with Python’s logging module, many of us have encountered confusion, as with the following code example:

import logging

log = logging.getLogger(__name__)
log.info('Hello')

We might expect this code to print the string Hello, but it doesn’t.

This is because the default log level for Python’s logging module is WARNING, so only messages at WARNING, ERROR, or CRITICAL levels are displayed.

To properly use the logging module, setting it up is necessary, which often means consulting the Python documentation. This isn’t a problem with Python per se, but rather a design philosophy difference.

So, is there a package more intuitive and easier to use than the built-in logging module?

The answer is “yes,” and that is the structlog package, which this article introduces.

Posted on  Aug 30, 2023  in  Python Module/Package Recommendations , Python Programming - Beginner Level  by  Amo Chen  ‐ 4 min read

Designed for Counting - Python Counter Class

The Python collections module provides several convenient classes for developers to use, among which the Counter class (a subclass of dict) can be applied in counting-related scenarios:

A Counter is a dict subclass for counting hashable objects.

This article will introduce the usage of the Counter class and compare its performance with dict and defaultdict.

Posted on  Apr 19, 2022  in  Python Programming - Beginner Level  by  Amo Chen  ‐ 5 min read

Python Module Tutorial - pathlib

Python’s os module provides many convenient functions for us to manipulate file/folder paths. After Python 3.4, a new module called pathlib was introduced, which encapsulates various file/folder related operations in classes such as Path, making file/folder operations more object-oriented.

This article will explain and demonstrate the pathlib module.

Posted on  Oct 19, 2020  in  Python Programming - Beginner Level  by  Amo Chen  ‐ 5 min read

Learn Python Multiprocessing Module Easily with Examples

Python’s built-in multiprocessing module is quite important if there are requirements for parallelism processing, in addition to the built-in threading module, another one is multiprocessing.

The advantage of using multiprocessing is that it can greatly avoid the impact of Python GIL on program performance, but the bad thing is that it consumes more memory. Even so, it is still a module that must be understood.

This article will learn how to use the multiprocessing module through several examples.

Last updated on  Feb 8, 2023  in  Python Programming - Beginner Level  by  Amo Chen  ‐ 8 min read

Pyenv - A great tool for Python version management

Python has been evolving for nearly 10 years, so the development of Python projects also needs to consider the issue of version.

Especially now that Python 2 has retired, most Python projects now use Python 3 as the main version, but some of the old projects in companies still use Python 2 for development, so developers must switch between Python 2 and 3.

If you have trouble switching between Python versions, then pyenv will be your best friend!

Last updated on  Mar 13, 2023  in  Python Programming - Beginner Level , Useful Python Modules  by  Amo Chen  ‐ 3 min read