Why does python not have a mechanism for data hiding?

Antoon Pardon apardon at forel.vub.ac.be
Tue Jun 3 03:41:02 EDT 2008


On 2008-06-03, Carl Banks <pavlovevidence at gmail.com> wrote:
> On Jun 2, 10:14 am, Antoon Pardon <apar... at forel.vub.ac.be> wrote:
>> On 2008-06-02, Carl Banks <pavlovevide... at gmail.com> wrote:

>> Can't you look beyond the specific example? The GetX is just an example.
>> Any local function of __init__ has access to hidden and its attributes
>> and could manipulate them, even if the class wouldn't define getters
>> and setters.
>
> Ok.  You could have made the proof-of-concept-ness of your example
> more clear by not, you know, binding those local functions to globally
> accessable names, thus thwarting your own concept.
>
> But still, we all knew functions could do that.

Well maybe you all knew that, yet while I read the thread, I saw
noone mentioning this possibility to get what the OP seemed to
want. I also did't see other posibilities. Your idea as an alternative
only came as a reaction to my idea.

I know my idea as presented was cumbersome. Maybe it can be worked out
more, maybe with the help of decorators to be less cumbersome.

I also know it can be circumvented in CPython.


Yet I think is was usefull to explore what is already possible in Python
instead of just argueing about whether people need it or not


I always find it odd when the "you don't need it" argument is used.
Of course that is correct, put python has acquired a lot of things
that were originnally labeled "you don't need it". So why people
still use it against introducing something, is something I don't
entirely understand.

-- 
Antoon Pardon



More information about the Python-list mailing list