I'm definitely still in the Python learning phase, but I've learned a little about the Python dunder methods (__init__
, __cmp__
, __add__
, etc.) and as best I can tell, these are ways that the core Python developers to allow programmers to implement special methods for their own classes.
So, it seems like those ought to be well-defined and limited to whatever the core developers specify. But today (as I'm starting to learn SQLAlchemy), I ran across their own attributes like __tablename__
and __table_args__
To me, that's confusing. I thought the Pythonic meaning of dunder methods or attributes implied that they were part of the core of Python. But SQLAlchemy appears to be using it as a convention to hide lower-level parts of their ORM.
Is this good practice? If I'm writing classes, should I feel free (or even be encouraged) to make up my own dunder attributes or methods?