Re: Am I just dreaming, or...

Guido.van.Rossum@cwi.nl
Mon, 08 Aug 1994 16:46:42 +0200

> Whoa, hold on. This was in fact my mistake. I misheard or
> misinterpreted some time in the past exactly the mechanism Steve is
> describing below. For some reson I thought the
> import-not-getting-"_attribute"s thing had something to do with dir as
> well. But the reason, I think, that I was thinking about dir() in
> this way is because I really do want some way to hide attributes from
> users. I have a bunch of internal data in some class instances that
> users can manipulate through method calls, but I would really prefer
> they not be mucking around with them directly. I suppose this is a job for
> the up-and-coming access object, but will access objects keep someone
> from even knowing about data attributes or will it just keep them from
> being able to manipulate them?

In general I think you're out of luck if you really want to hide the
presence or implementation of objects in Python. Access won't help
you here. Why do you think you need such draconic measures? Can't
you just give them a name starting with an underscore or write "#
INTERNAL USE ONLY" in the source code? In the end there's no way to
stop a dedicated hacker from finding out about your code. "access"
should be sufficient to avoid accidentally stepping on internal state.
A naming convention should stop people from wondering "what's this
variable for...?"

--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
<URL:http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>