Today I became aware of the existence of the builtin Python module fractions. The fractions module handles rational number arithmetic. Here's a simple example using the Fraction class to covert a decimal into a Fraction with the numerator and denominator reduced to the lowest terms. My ...
python
Avoid using mutable values as default parameter values in Python (Today I Learned)
Today I learned something interesting about the way Python functions behave with default parameter values: avoid using mutable objects such as lists as default values for function parameters. What's the problem? Default parameter values are evaluated when function is evaluated. Which means ...
How to watermark images with Python and Pillow (PIL)
I am a DIY blogger, and the most tedious part of the job is editing the images. I am constantly repeating the following steps: Resize the imageAdd a text watermarkCompress the image I wanted to automate the process. There are good solutions out there for automating image manipulation, but it ...