A Guide to Python's Magic Methods « rafekettler.com

22 bookmarks. First posted by hellified july 2017.

A guide to all the Magic Methods in Python
programming  python 
3 days ago by kger
This guide is the culmination of a few months' worth of blog posts. The subject is magic methods.

What are magic methods? They're everything in object-oriented Python. They're special methods that you can define to add "magic" to your classes. They're always surrounded by double underscores (e.g. __init__ or __lt__). They're also not as well documented as they need to be. All of the magic methods for Python appear in the same section in the Python docs, but they're scattered about and only loosely organized. There's hardly an example to be found in that section (and that may very well be by design, since they're all detailed in the language reference, along with boring syntax descriptions, etc.).

So, to fix what I perceived as a flaw in Python's documentation, I set out to provide some more plain-English, example-driven documentation for Python's magic methods. I started out with weekly blog posts, and now that I've finished with those, I've put together this guide.

I hope you enjoy it. Use it as a tutorial, a refresher, or a reference; it's just intended to be a user-friendly guide to Python's magic methods.
python  programming  bestpractices  reference  magicmethods 
4 days ago by jotjotjes
A guide to all the Magic Methods in Python
7 days ago by geetarista
A guide to all the Magic Methods in Python
python  bestpractices 
7 days ago by synergyfactor
Documenting magic in Python
from twitter_favs
8 days ago by jim68000