Ben Chuanlong Du's Blog

And let it direct your passion with reason.

Python Logging

General Tips

  1. logging is a Python module for logging coming with the standard library while loguru is a popular 3rd-party logging library. Unless you do not want your Python package/script to depend on 3rd-party libraries, loguru is preferred to logging for multiple reasons.

    • loguru is easy and fun to …

Hands on the Python Module argparse

  1. argparse is the best library to use to parse command-line arguments in Python. It is included in Python standard libaries (which menas that you can use it out of the box).

  2. It is suggestedd that you always log a parsed Namespace object so that you can check whether it is as expected.

Static Type Checking of Python Scripts Using pytype

Configuration

There are 3 ways to control the behavior of `pytype.

  1. Pass command-line options to pytype.

  2. Specify a configuration file using pytype --config /path/to/config/file .... You can generate an example configuration file using the command pytype --generate-config pytype.cfg.

  3. If no configuration file is found, pytype uses the …