Why are Python's 'private' methods not actually private?

后端 未结 12 2343
不思量自难忘°
不思量自难忘° 2020-11-22 02:50

Python gives us the ability to create \'private\' methods and variables within a class by prepending double underscores to the name, like this: __myPrivateMethod()

12条回答
  •  佛祖请我去吃肉
    2020-11-22 03:00

    It's not like you absolutly can't get around privateness of members in any language (pointer arithmetics in C++, Reflections in .NET/Java).

    The point is that you get an error if you try to call the private method by accident. But if you want to shoot yourself in the foot, go ahead and do it.

    Edit: You don't try to secure your stuff by OO-encapsulation, do you?

提交回复
热议问题