"Private" attributes - a possible idea (maybe PEP-worthy).
Delaney, Timothy
tdelaney at avaya.com
Wed Jan 30 19:21:04 EST 2002
> From: Skip Montanaro [mailto:skip at pobox.com]
> Tim> a.Klass -> _1__attr1 and _1__attr2
> Tim> b.Klass -> _2__attr1 and _2__attr2
>
> This would be unworkable. Private attributes couldn't be pickled.
Damn - knew there had to be *something* big against it.
However, I can't help but feel that there must be *some* way to enforce that
a "private" variable won't be accidentally used by a subclass.
Hmm - would it be possible to save a class:id mapping in the pickle, and
have the private attributes re-written with the "real" class ID when
unpickling? No - don't think that would be possible - and would be
undesirable - we need a solution that doesn't require a change to the pickle
code (and hence everything that emulates the pickle code).
Any other ideas of how to get around this problem?
Unfortunately, whilst it's not a problem that is likely to crop up commonly,
it's one that when it *does* crop up is likely to cause real debugging
headaches. It is also (IMO) a wart in the language because it can cause such
obscure problems.
Tim Delaney
More information about the Python-list
mailing list