Skip to content

Entries published on November 15, 2015

1 entry published on this date. See also: all entries published in November 2015, full archive.

A real Python “wat”

A few weeks ago I went through and explained the various items in a list of “Python wats” — behaviors of Python which seemingly made no sense. Calling them “wats” is a bit of a stretch in most cases, though, because most of them were simply consequences of fairly reasonable design decisions in how Python or its standard libraries work, but presented in ways which obscured what was actually going on.

Lest I be accused of defending Python too much there, I’d like to point out an absolutely genuine “wat” moment in Python that I helped someone with recently.

On reddit, someone was asking about Django’s length template filter, and specifically its behavior with an undefined variable. The bit of template in question was something like:

{% if some_var|length > 1 %}
    It's more than 1
{% else %}
    It's not more than 1
{% endif %}

When some_var was undefined …

Entry published November 15, 2015. Read full entry.