Posts tagged “Programming”

Exhaustive Union Matching in Python

January 12, 2022 – tagged Python, Programming

This blog post has been published on the Preferred Networks Tech Blog.

Pattern matching on algebraic data types is a powerful technique to process a given input and many programming languages have adopted it in one way or another. In this blog post I will first briefly explain the concept of sum types and give examples of pattern matching on these types in Rust and Scala. Then I will show how to define sum types in recent Python versions, and I will explain how the mypy type checker can (to a limited degree) be used to add exhaustiveness checks to Python code working with these types.

Best Practices for Working with Configuration in Python Applications

April 24, 2020 – tagged Python, Programming

This blog post has been published on the Preferred Networks Tech Blog.

Most computer applications can be configured to behave a certain way, be it via command line flags, environment variables, or configuration files. For you as a software developer, dealing with configuration comes with challenges such as parsing untrusted input, validating it, and accessing it on all layers of your program. Using Python as an example, I want to share some best practices to help you handle configuration safely and effectively.

Parsing timestamps from Apache log files in Python

October 29, 2013 – tagged Apache, Programming

Timestamps in Apache access log files have, by default, the format 27/Oct/2013:06:33:40 +0100. This can not be parsed in Python using the strptime() function from the time/datetime modules because there is no %z placeholder in strptime() to match the timezone (only %Z). Also, using the parse() function from dateutil.parser ...