Personal tools

Sep 10, 2014

Play these (Python) strings until my fingers are raw

What Do You Want from Me

Play these (Python) strings until my fingers are raw

Filed Under:

This blog post is about the tricky task of subclassing immutable types in Python. Once you get it right, you will end up with superpowered objects

In one project I had to subclass the Python string type (namely str) in order to get some additional features.

Why I decided to do that?

Because I needed something:

  • supporting almost all the methods of the standard strings
  • with some custom attributes, additional methods
  • that could be compared and mixed with strings.

I had almost no choice. But subclassing str is a task that should be handled with special care because it is a so called immutable type.

read more