Search code examples
pythonprivate

True privateness in Python


PEP 8 states that (emphasis mine):

We don't use the term "private" here, since no attribute is really private in Python (without a generally unnecessary amount of work).

I guess it refers to defining the actual class in some other language and then exposing only the public members to the interpreter. Is there some other way to achieve true privateness in Python?

I'm asking just out of curiosity.


Solution

  • No, nothing is truly private in Python.

    If you know the method name, you can get it.

    I think you might come up with a clever hack, but it would be just that - a hack. No such functionality exists in the language.