Why does python not have a mechanism for data hiding?

sturlamolden sturlamolden at yahoo.no
Tue Jun 3 20:04:54 CEST 2008


On Jun 2, 12:40 pm, Antoon Pardon <apar... at forel.vub.ac.be> wrote:

> I think you completed missed the point.
>
> This is just a proof of concept thing. In a real example there would
> of course no Set en Get methods but just methods that in the course
> of their execution would access or update the hidden attributes

I have to agree with Banks here, you have not provided an example of
data hiding. It does not discriminate between attribute access from
within and from outside the class. You just assume that the attribute
named 'hidden' will be left alone. Also naming it hidden is stupid as
it is visible.

What you need is a mechanism that will thrown an exception whenever an
attribue is accessed from outside the class, but not from inside.

The mechanism must also be impossible to override with additional
code.

If Ada is what you want, Ada is what you should use.










More information about the Python-list mailing list