Slots seem to be poorly documented. What they do is simple, but whether they are used is tricky. This is a little mini-post on slots.
[Read More]Basics of metaclasses
This is a quick tutorial over the basics of what metaclasses do.
The Metaclass
Metaclasses, while seemingly a complex topic, really just do something very simple. They control what happens when you have code that turns into a class object. The normal place they are executed is right after the class statement. Let’s see that in action by using print as our metaclass.
[Read More]Factory classmethods in Python
I haven’t seen a great deal of practical documentation about using classmethods as factories in Python (which is arguably the most important use of a classmethod, IMO). This post hopes to fill in that gap.
[Read More]Making an autoload extension for IPython
Uncertainty extension for IPython
Wouldn’t it be nice if we had uncertainty with a nice notation in IPython? The current method would be to use raw Python,
from uncertainties import ufloat
print(ufloat(12.34, 0.01))
12.340+/-0.010
Let’s use the infix library to make the notation easier. We’ll define |pm|
to
mean +/-
.
Plumbum color
I’ve been working on a color addition to Plumbum for a little while, and I’d
like to share the basics of using it with you now. This library was originally
built around a special str
subclass, but now is built on the new Styles
representation and is far more powerful than the first implementation. It safely
does nothing if you do not have a color-compatible systems (posix + tty
currently), but can be forced if need be. It is included with Plumbum, so you
don’t have to add a requirement for your scripts that is non-essential (as color
often is). It is integrated with plumbum.cli
, too. Also, I’ve managed to
accelerate the color selection algorithms about 8x, allowing near game-like
speeds. (see the fullcolor.py
example).