Blog posts in category “Batteries included”
A series of blog posts about Python's standard library.
-
Aug 31st, 2024Blaugust 2024 retrospective
Another Blaugust finished with 31 posts in 31 days. I got to share my love for Python and its standard library over a series of posts that hopefully inspired readers to learn something new.
-
Aug 30th, 2024Book recommendation: Fluent Python (2nd Edition)
Fluent Python is one of the best - if not the best - Python books and will help you become better at writing pythonic code.
-
Aug 29th, 2024What’s coming to Python in 3.13 and 3.14
With new Python versions in the horizon, what goodies can we expect to see?
-
Aug 28th, 2024Couple of great Python podcasts
Python community has so many great podcasts to learn more from. Here are 4 picks of the ones I’ve been mostly listening lately.
-
Aug 27th, 2024Quick prototyping with sqlite3
Python’s sqlite3 bindings makes it a great tool for quick prototyping while you’re working out what it is exactly that you’re building and what kind of database schema makes sense.
-
Aug 26th, 2024Parse command line arguments with argparse
In 2021 I wrote a blog post documenting argparse in a way that made more sense to me. This year for Blaugust and Batteries included, I want to resurface that for those who are new to argparse.
-
Aug 25th, 2024Pretty print and validate JSON on command line with json.tool
Python has a variety of command line interfaces that can be run without writing any code or starting a REPL. Json module has one that I use quite regularly.
-
Aug 24th, 2024Test your codebase with unittest
Few weeks ago I wrote about doctest and today, I’m looking into another way to write tests that is built in to Python: unittest.
-
Aug 23rd, 2024Branch out with pattern matching
Since Python 3.10, Python has had support for pattern matching which is made it my all-time most anticipated release when it came out. It makes branching while capturing data to variables a breeze once you get used to it.
-
Aug 22nd, 2024Serve local HTML and CSS files with http.server
python -m http.server provides a handy way to spin up a local server for your files.
-
Aug 21st, 2024Bring your custom toolkit to REPL sessions
You can bring in your favourite tooling and most used imports to every REPL session with environment variable PYTHONSTARTUP.
-
Aug 20th, 2024Keep track of happenings with logging
Python provides good basic functionality for logging in its standard library.
-
Aug 19th, 2024Memoize with functools.cache
Do you have computationally expensive functions that are called often? Memoizing is a strategy that caches results in memory so the full computation can be skipped in future calls.
-
Aug 18th, 2024map and filter with list comprehensions
Python has map and filter functions but we like to use list comprehensions instead because they flow off the tongue so smoothly.
-
Aug 17th, 2024Combine iterables with zip
Combine or iterate over multiple iterators at once by zipping them together.
-
Aug 16th, 2024Random number chosen by fair dice roll
Python’s random module offers tools to generate pseudo-random numbers.
-
Aug 15th, 2024Write more pythonic code with context managers
Context managers enable you to create “template” code with initialisation and clean up to make the code that uses them easier to read and understand
-
Aug 14th, 2024Combinatoric iterators from itertools
itertools module offers four combinatoric iterators that generate different combined outputs from one or more iterable.
-
Aug 11th, 2024Data classes in Python with dataclasses
Python has a couple of methods to implement data class pattern. Last week, I looked into namedtuples and today, I’m writing about a newer option: dataclasses.
-
Aug 10th, 2024Rotating turn order with deque
deque is a double-ended queue that I’ve used to implement rotating turn order for a (very simplified) game engine.
-
Aug 9th, 2024Debug with pdb and breakpoint
Python’s standard library comes with good tooling to debug your code – and a lot of community-made tooling that can be configured to take your debugging productivity to a whole new level.
-
Aug 8th, 2024Document intended usage through tests with doctest
There’s a lot to like about Python’s doctest module. It enables you to write tests as examples in your documentation, fulfilling two important duties of tests.
-
Aug 7th, 2024Improved print readability with pprint
Pretty print module provides more readable prints for complex data structures
-
Aug 6th, 2024help() me Obi-Wan Kenobi, you’re my only hope
Python’s built-in help system is your companion when developing or debugging Python code.
-
Aug 5th, 2024Count ‘em
Python’s Counter provides a way to count items in iterables or mappings and get them in a dictionary-like object with a small handful of handy methods.
-
Aug 4th, 2024Improve your code with namedtuples
We continue our journey in Python standard library by taking a look one of my absolute favorites: namedtuple. It’s like a regular tuple but adds documentation, making your code cleaner and easier to read.
-
Aug 3rd, 2024Reading and writing CSV with Python
Python has great tools for reading and writing data in CSV format.
-
Aug 2nd, 2024Parsing nginx server logs with regular expressions
Regular expressions are fun. In this series of Batteries included, I write about Python’s standard library with practical examples.
-
Aug 1st, 2024Blaugust 2024: Batteries included
August’s blogging festival Blaugust is here again and this year, I’m writing about the goodies in Python’s standard library.