Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
PHP ("magic methods") and Javascript also have this. Open your browser console and type Array.__lookupGetter__ or Object.__proto__. It is a naming convention used in multiple languages for methods that can (or should) only be executed directly from inside the object/class instance itself. By prefixing them with a double underscore, it avoids naming clashes with methods a developer would define.
-
Because they wanted to reserve init() for user defined functions (see the flask documentation).
-
Because in python, functions and variables that you aren't supposed to call directly, but rather using operators or language features, are named like that.
__eq__
__getattr__
__repr__
They are pretty consistent about that. Just the way it is. It prevents it from clashing if you accidently make an init function and reduces the list of forbidden keywords.
Can someone explain the reasoning for why we can't use init instead __init__? I'm learning and this is breaking my brain.
rant
python __init__