RSSAmplifier

Blog

James Bennett (b-list.org)

b-list.orgRSS feed ↗15 posts

Latest posts

Breaking up (lines) is hard to do

Here’s a seemingly simple question: given a chunk of multi-line text, how do you split it and return an array whose members are the constituent lines of the text? Hopefully, your first instinct is to reach for some sort of standard-library function, maybe something like the splitlines() method of Python’s str type. Because it turns out this “simple” question is actually pretty complex to answer!…

Let’s talk about LLMs

Everybody seems to agree we’re in the middle of something , though what, exactly, seems to be up for debate. It might be an unprecedented revolution in productivity and capabilities, perhaps even the precursor to a technological singularity beyond which it s impossible to guess what the world might look like. It might be just another vaporware hype cycle that will blow over. It might be a…

Rewriting a 20-year-old Python library

Way back in 2005, lots of people (ordinary people, not just people who work in tech) used to have personal blogs where they wrote about things, rather than using third-party short-form social media sites. I was one of those people (though I wasn’t yet blogging on this specific site, which launched the following year). And back in 2005, and even earlier, people liked to have comment sections on…

Litestar is worth a look

A few years ago at work, I had a project which offered an opportunity to look at the new generation of async-first, type-hint-driven Python web frameworks. For reasons which aren’t particularly relevant today, on that project I ended up choosing Litestar , which is the one that doesn’t have a ravenous all-consuming hype machine surrounding it. And I’m very glad I did, because today I’m more…

Introducing DjangoVer

Version numbering is hard, and there are lots of popular schemes out there for how to do it. Today I want to talk about a system I’ve settled on for my own Django-related packages, and which I’m calling “DjangoVer”, because it ties the version number of a Django-related package to the latest Django version that package supports. But one quick note to start with: this is not really “introducing”…

Three Django wishes

’Tis the season when people are posting their “Django wishlists”, for specific technical or organizational or community initiatives they’d like to see undertaken. Here are a few examples from around the Django community: Sarah Boyce Tim Schilling Andy Miller Emma Delescolle So, in the spirit of the season, here is my own list, which I’ve narrowed down to three wishes (in the tradition of many…

There can't be only one

There s a concept that I ve heard called by a lot of different names, but my favorite name for it is the Highlander problem , which refers to the catchphrase of the campy-yet-still-quite-fun Highlander movie/ TV franchise. In Highlander , immortal beings secretly live amongst us and sword-fight each other in hopes of being the last one standing, who will then get to rule the world forever. And…

Know your Python container types

This is the last of a series of posts I m doing as a sort of Python/Django Advent calendar, offering a small tip or piece of information each day from the first Sunday of Advent through Christmas Eve. See the first post for an introduction . Python contains multitudes There are a lot of container types available in the Python standard library, and it can be confusing sometimes to keep track of…

Compare strings the right way

This is part of a series of posts I m doing as a sort of Python/Django Advent calendar, offering a small tip or piece of information each day from the first Sunday of Advent through Christmas Eve. See the first post for an introduction . Unicode s unique complexity It is the year 2023 almost 2024! and hopefully you re using a programming language that is fully Unicode-aware. Python is; its string…

Set cookies the right way

This is part of a series of posts I m doing as a sort of Python/Django Advent calendar, offering a small tip or piece of information each day from the first Sunday of Advent through Christmas Eve. See the first post for an introduction . Cookies in the cookie jar Django s request and response objects, and their attributes and methods, make dealing with cookies easy. You can read from the…

Don't use Python's property

This is part of a series of posts I m doing as a sort of Python/Django Advent calendar, offering a small tip or piece of information each day from the first Sunday of Advent through Christmas Eve. See the first post for an introduction . Attributing the problem Suppose you re writing Java and you write a class with an attribute : public class MyClass { public int value ; } And then later on you…

Use Django's system checks

This is part of a series of posts I m doing as a sort of Python/Django Advent calendar, offering a small tip or piece of information each day from the first Sunday of Advent through Christmas Eve. See the first post for an introduction . Check it out While you can do very minimal Django setups, more typical use cases tend to involve a mix of applications your own, some third-party, and some from…

Show Python deprecation warnings

This is part of a series of posts I m doing as a sort of Python/Django Advent calendar, offering a small tip or piece of information each day from the first Sunday of Advent through Christmas Eve. See the first post for an introduction . Let this be a warning Python provides the ability to issue a warning as a step below raising an exception; warnings are issued by calling the warnings.warn()…

Running async tests in Python

This is part of a series of posts I m doing as a sort of Python/Django Advent calendar, offering a small tip or piece of information each day from the first Sunday of Advent through Christmas Eve. See the first post for an introduction . A-sync-ing feeling Async Python can be useful in the right situation, but one of the tricky things about it is that it requires a bit more effort to run than…

Don't use class methods on Django models

This is part of a series of posts I m doing as a sort of Python/Django Advent calendar, offering a small tip or piece of information each day from the first Sunday of Advent through Christmas Eve. See the first post for an introduction . Being methodical about Python Python classes support three basic types of methods: Instance methods , which are what you get by default when writing a def…