Metaclasses in Python

Posted on Jan 11, 2014 (14 weeks ago). Seen 441 times. No comments. Permalink Feed
Photo Evan Davis
Media Producer
NewCircle, Inc.
Member since Jan 14, 2013
Stream Posts: 100
Tagged as: Python SF Python Video

Metaclasses take the mantra “everything is an object” to the next level. One of Python’s fascinating lesser-known features, they allow you to intervene on the creation of classes themselves, and not just their instances. So in other words, metaclasses are like classes for classes, but when would you ever need them?

While it is rare to genuinely need a metaclass, they are a fun feature to know about and play with. In this talk for SF Python, Jess Hamrick explains how metaclasses work, why you might want to use them, and provides examples from her own adventures using metaclasses to rewrite method docstings to be prefixed with the name of the class they belong to.

To continuing diving into Python, browse our stream of free Python resources, or check out our list of upcoming Python trainings.

Comments

Be the first one to post a comment!