Metaclasses in Python

Metaclasses in Python

Photo Evan Davis
Lead Video Producer
NewCircle, Inc.
Member since Jan 14, 2013
Stream Posts: 187
Posted on Jan 11, 2014 (1 year ago)
Seen 976 times.
Tagged As:

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.


You have to login to post a comment.