Forcely make "private method or property" invisble and cannot be accessed directly

"WeiTung" <[email protected]> Mon, 25 May 2026 17:16:10 +0800
Newsgroups gmane.comp.python.general
Message-ID <[email protected]>
This is a multipart message in MIME format.

--===============3661929766820052265==
Content-Type: multipart/signed;
	protocol="application/x-pkcs7-signature";
	micalg=2.16.840.1.101.3.4.2.1;
	boundary="----=_NextPart_000_0000_01DCEC6A.2E75C1B0"
Content-Language: zh-cn

This is a multipart message in MIME format.

------=_NextPart_000_0000_01DCEC6A.2E75C1B0
Content-Type: text/plain;
	charset="gb2312"
Content-Transfer-Encoding: quoted-printable

Hello all:

	Until now we see if you have a class like this following in Python

		class MyClass:
    		__myPrivateMember =3D 0

    		def __myPrivateMethod(self):
        		# Here goes with what you want freely
        		pass

=A1=A1=A1=A1mc =3D MyClass()
=A1=A1=A1=A1mc._MyClass__myPrivateMethod()

	Here we can still play with "__myPrivateMethod " by giving the
auto-generated prefix (this has been a public secret, you know), so =
it=A1=AFs
also for the "__myPrivateMember ".
	What I wanna say is, this isn't a good idea, because since it's
private, why could we still access it? We must abandon anyone to access =
it
anyway.
=09
	Maybe we should generate some random string (such as address of
method/property?) or something like it? This means everytime when we run =
the
code, the "private" thing is random after compiling, only the Python =
system
itself know how to access it.
	For those who directly access the "private" things, compiler SHOULD
give them an error, and when running , "AttributeNotFound" still occurs.
	That's all my idea for good practice of programming in OOP for
Python.

-----
This email is signed by the free S/MIME certificate of =
=A1=B0CerSign=A1=B1
(https://www.cersign.com/smime-email-certificates.html)

Be sure to import the root certificate of =A1=B0CerSign Identity RSA =
Root=A1=B1 into
your trust root certificate list for encryption, download it from
https://www.cersign.com/root/rsa.html

If you see =A1=B0smime.p7s=A1=B1 in my letter, you can ignore it because =
your
mailbox doesn=A1=AFt support S/MIME


------=_NextPart_000_0000_01DCEC6A.2E75C1B0--


--===============3661929766820052265==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline