Stupid, yet common mysteries demystefied

Does python have access specifiers?

Short Answer: No, it does not. The top answer on StackOverflow is perfect. The philosophy behind access specifiers is,

It’s not about forbidding access or hiding something, it’s about implicit API documentation. Developers as well as compilers/interpreter/code-checker easily see which members are recommended to be used and which ones shouldn’t get touched (or at least with care). In most cases it would be a horrible mess if all members of a class or module were public. Consider the distinction of private/protected/public members as a service, saying: “Hey, these members are important while those are used internally and probably not useful for you.”

– Oben Sonne

Then why is the book littered with class names, method names that start with _<name>?

That’s a convention followed by all Python Developers, and you should (understand and) follow it too. How is this convention useful and who implements it? As noted above, most IDEs and other dev-services understand this convention.

The proof shows you the configuration of a docstring parser called Napolean. Napolean is used by Sphinx, an automated documentation generator. You can see that the parser can be told not to auto-document the “private” functions, methods and attributes.

What is self? Is it same as this->?

See what Guido has said on “why explicit self has to stay”.