"Private" attributes - a possible idea (maybe PEP-worthy).

Skip Montanaro skip at pobox.com
Wed Jan 30 19:03:38 EST 2002


    Tim> My proposal would be that rather than forming private variable
    Tim> names like _<class name>__attr (e.g. _Klass__attr) they should
    Tim> instead be defined as _<class id>__attr. It is guaranteed that
    Tim> there is only one object with a particular ID at any one time.

    Tim> So, using the code above, if id(a.Klass) == 1 and id(b.Klass) == 2
    Tim> we would end up with 4 attribute names rather than the 2 we have
    Tim> currently:

    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.

-- 
Skip Montanaro (skip at pobox.com - http://www.mojam.com/)




More information about the Python-list mailing list