To make a method or attribute private

Chris Angelico rosuav at gmail.com
Sun Jan 20 23:46:07 EST 2013


On Mon, Jan 21, 2013 at 2:27 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> On Sun, 20 Jan 2013 17:14:36 -0800, iMath wrote:
>
> [...]
>> so there is no REAL private variable in Python but conversion exists in
>> it that python programmer should follow and recognize .right ?
>
> There are no "REAL private variables" in most languages. Consider the C++
> trick "#define private public". Or pointer tricks, or using reflection in
> Java.

Uhh, that's like saying there are no REAL floats in C, because you can
#define float int
And pointer tricks, well, you can do anything with raw memory access.
These aren't proofs that something doesn't exist, they're proofs that
trying to enforce privacy is bound to fail - so you may as well strip
that code from your compiler/interpreter and go with the Python style.
Much easier.

I agree with your point, just not your argument. :)

ChrisA



More information about the Python-list mailing list