I was wondering, is it recommended/Pythonic to define and use custom double underscore variables/functions in a Python script? For example, __tablename__
as used in SQLAlchemy or __validateitem__()
(a custom function that validates an item before applying __setitem__()
to it).
If it does define that something magic happens, or that that specific variable/function is used indeed in a special way (like the two above examples), I feel it is a good idea using them.
I am interested in arguments on both best coding practices and potential risks in using this kind of naming.
From PEP8:
So, the advice is not to use the double underscore syntax for your own variables.