Re: Change "__propertyName" or "__functionName" as invisible parts in a class forcely

Chris Angelico via Python-list <[email protected]> Wed, 27 May 2026 04:28:30 +1000
Newsgroups gmane.comp.python.general
Message-ID <CAPTjJmrXVXP3K7PCwd+uSFYf0TjMQJKRd3wDFFQwDV2zqa8hzA@mail.gmail.com>
On Wed, 27 May 2026 at 04:16, <[email protected]> wrote:
>
> As u all know, when we're starting to define a private member or a function in Python, led by "__", some like this following:
>
> class MyClass:
>
>     __privateMember = your initValue Here
>
>     def __myPrivateMethod(self):
>         # do what u want here...
>
> Now you can still access the private member or private method through the "_MyClass__myPrivateMethod()" or "_myClass__privateMember".
>
> What I wanna say here is:
>
> 1. This WON'T give those who begin to learn Python a good understanding of "private method/private member" for OOP,.
> 2. Since it's private, why could we still access them? It will sometimes gives a programmer a bad / lazy way of assignment to the private things.
>

They are not private. You're under a very much mistaken impression.
They've never been private and there's no intention ever to make them
private.

ChrisA