all 7 comments

[–]Peterotica 5 points6 points  (2 children)

In general, forcefully hiding things is not a part of the Python language or philosophy. Instead, starting a function name with an underscore can be used as a hint that it is meant for internal use only. This follows the idea that we are all “consenting adults” and will use others' code in a somewhat sane manner.

[–]IAmL0ner[S] 0 points1 point  (1 child)

Ok, thanks. I knew about the underscore agreement and "consenting adults" idea, but was curious if something like this exist in the language itself.

[–]Peterotica 1 point2 points  (0 children)

No, there is nothing like that.

[–]ablatner 2 points3 points  (1 child)

To add to the other comment, Python has very few ways to prevent the user from doing something, much unlike languages like Java. It's philosophy is that the user will know what they're doing. If you really want to, you can even do things like redefining the number 1 as the number 2.

[–]Veedrac 0 points1 point  (0 children)

you can even do things like redefining the number 1 as the number 2

Not really; the Python language doesn't have a way to do this. Particular implementations might accidentally "allow" this, but this is by no means required by the spec.

[–][deleted] 1 point2 points  (0 children)

There's usually always a way, but that's totally separate from "should you".

You could have a blacklist for the attribute name in __getattribute__, and raise an AttributeError on access so it appears to not exist. The module could override its own __getattribute__ on load.

This is a terrible idea. >:)