January 18, 2023

Your First Contribution to CPython

Do you love Python? I certainly do. Have you ever thought how cool it would be to contribute to it? Sounds scary? It is not! Python, or more specifically CPython as the reference implementation of the Python programming language is called, is an open source project like any other - nothing magical. Other resources While there are many great resources out there to prepare you for the first contribution, such as...

July 5, 2022

How f-strings Handle Double Curly Braces

Today I was about setting up a test case for parsing a YAML file which is templated with Jinja variables. Something like this… f""" pipeline: - test jobs: test: package-repositories: - type: apt url: "https://{{auth}}@example.org" """ My test case failed… My Pydantic model, which uses yaml.safe_load under the hood to load the above configuration, returned the URL, even before the value got replaced, as https://{auth}@example.org. One pair of the double curly braces was stripped away!...

June 27, 2022

Ubuntu Versions Cheat Sheet

about versions, names, even more versions and dates version code name python go debhelper end of standard support eol 16.04 xenial xerus 3.5 ? 9 04/2021 04/2026 18.04 bionic beaver 3.6 ? 11 04/2023 04/2028 20.04 focal fossa 3.8 1.13 + 1.14 12 04/2025 04/2030 22.04 jammy jellyfish 3.10 ? 13 04/2027 04/2032 24.04 noble numbat 3....

May 23, 2022

Conda, Miniconda and 2x Anaconda

While I certainly heard of Conda, Miniconda, and Anaconda before, I only had a vague idea of these terms and what is behind them. So, let’s get the terminology straight. Conda… what? Conda Conda is a CLI application which does package, dependency and environment management, not only for Python, but also for other languages. Anaconda Anaconda is an open-source Python distribution platform. This is the all-in-one package, containing not only the Conda application, but already many packages which you usually need for a data science project....

April 16, 2022

getattr() Considered Harmful

While Hynek already considered “Considered Harmful” was getting old in 2016, and so he named this blog post hasattr() – A Dangerous Misnomer, instead of hasattr() considered harmful, meanwhile it is 2022 and I still like that phrase. So here we go… getattr() considered harmful The setting is a CLI application with 100% test coverage, and even branch coverage is activated. coverage 101 I assume you know what coverage is. 100% test coverage means that the test suite covers all lines of code of your library or application....

November 9, 2021

Bye-Bye python-memcached, hello pymemcache

For one app that I help maintaining I noticed that python-memcached was used, which has not been updated in several years. There were some efforts to transfer python-memcached to a new maintainer, but at the end that did not work out. So, the project is dead. While an unmaintained project may currently work, there are several things to consider: there may be bugs which do not get fixed there may be security issues which do not get fixed it may stop working for e....

May 22, 2021

Variable Scope and List Comprehensions

Python 2 In Python 2 the temporary variable was not so temporary at all… ❯ python2 Python 2.7.17 (default, Feb 27 2021, 15:10:58) [GCC 7.5.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> s = "abc" >>> [x for x in s] ['a', 'b', 'c'] >>> x 'c' As you can see, x leaks outside the scope the list comprehension. Python 3 This has been changed in Python 3....

January 11, 2021

How to Install a Python Package Directly From a Git Branch From GitHub

Bernát Gábor is currently working on a complete rewrite for tox. I alpha-tested the latest release (4.0.0a2), and reported a couple of problems. Within a day Bernát published some fixes on the rewrite branch, and asked me to test it. That means there is no new package on PyPI, yet. So, I had to install tox directly from GitHub, to be exact, from the rewrite branch: pip install git+https://github.com/tox-dev/tox@rewrite or more general...

December 3, 2020

What Is the Difference Between Invoking `pytest` and `python -m pytest`

Yesterday, I was recommended to have a look at Shopyo - Open inventory management and Point of sales. As I am passionate about testing and CI, I always have a look at configuration files for newly discovered projects. After I cloned the repository, I tried to run the tests. So, without having a look into the documentation ( :-/ ), I created a virtual env installed the dependencies ran pytest from the root of the project … and got a ModuleNotFoundError The friendly maintainers of the projects pointed me in the right direction on how to run tests for this project:...

November 13, 2020

How to Group Data Easily With SimpleNamespace

While you could use the usual suspects, like a dictionary, a NamedTuple, a dataclass, or even an “empty” class, there is yet another way: SimpleNamespace. >>> from types import SimpleNamespace >>> simple_ns = SimpleNamespace(a=1, b="two") >>> simple_ns namespace(a=1, b='two') >>> simple_ns.a 1 >>> simple_ns.b 'two' >>> implementation This builtin is implemented in C, but the Python docs show how it would look like in Python: class SimpleNamespace: def __init__(self, /, **kwargs): self....