I want to see all the variables

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Mon Jan 1 06:14:13 CET 2007

On Sun, 31 Dec 2006 19:48:55 -0800, Tom Plunket wrote:

> Steven D'Aprano wrote:
>> What does the author of the original class know about *my* needs and
>> requirements?
> The only thing that the original class author might know is that mucking
> with data marked private may well cause problems, and hiding it
> therefore prevents those problems.

Sure. That's the risk I take when I muck about with somebody else's
private attributes.

>> It may turn out that accessing his "private" attributes is exactly what
>> I need to solve my problem.
> It may also turn out that you /think/ that's what you need to do, but
> actually need to do something different.

And how is that different from *any* programming task? I might think I
need a binary tree, when all I really need is a simple list. An error is
an error, whether it is with a public API or a private one. 

> E.g. it may well be possible to access the bytes on the disk that holds
> your database directly, and that may be "easier" than going through the
> db API, but doing so may also be highly prone to error.

No, I doubt it is "easier" -- but if I'm programming a database recovery
tool that fixes corrupted databases because the db vendor's supplied
tool is broken or non-existent, that might be exactly what I need to do.

>> I'm with the Python philosophy on this one: post all the "Don't Touch
>> This" warning signs you like, but if somebody really wants to access my
>> private attributes, to do something I never even imagined, they should
>> be allowed to.
> You are allowed to.  Have you been following the thread?  Your answer's
> been mentioned several times.

Yes, mostly by me. Do try to keep up.

> At the same time, you should ponder very
> carefully the reasons why the original author deemed it important to
> make those attributes private in the first place.

In my experience, it is mostly because they come from
bondage-and-domination languages where it is expected that everything is
private except for a small, carefully chosen public API, rather than from
languages like Python that encourages openness and a philosophy of "we're
all adults here".

I wonder how many double-underscore "private" attributes are used in the
Python standard library? That should give you an idea of "best practice"
use of private attributes in Python.


More information about the Python-list mailing list