Python’s Magic Methods
The Web Dev Zone is brought to you in partnership with Mendix. Discover how IT departments looking for ways to keep up with demand for business apps has caused a new breed of developers to surface - the Rapid Application Developer.
Here are some links to documentation of Python’s magic methods, aka special methods, aka “dunder” (double underscore) methods.
- Rafe Kettler’s A Guide to Python’s Magic Methods
- Michael Foord’s chapter on Python Magic Methods from this book IronPython in Action: Unleashing .NET with Python
- David’s article on Siafoo on Python __Underscore__ Methods
- The Python Quick Reference on John Shipman’s wonderful New Mexico Tech web site
- The official Python Language Reference
- Kumar McMillan’s post on Magic Methods on his FarmDev blog has a few interesting observations
There are also a few other Python features that are sometimes characterized as “magic”.
- some of the built-in functions, especially that newcomer: super()
- decorators that use some of the new built-in functions — @staticmethod, @classmethod, and @property
I’m sure there are other useful Web pages about magic methods that I haven’t found. If you know of one (and feel like sharing it) please add it in the comments section below.