Suppose I have a class, and I want to reference some elements in the ' __dict__
(for instance, I want to copy the dict and delete the attribute that cannot be pickled), from inside the class.
Problem is, those attributes are "private" so my code ends up looking like so
class MyClasss(object):
def __init__(self):
self.__prv=1
def __getstate__(self):
ret=self.__dict__.copy()
del ret['_MyClass__prv']
I reference the class name explicitly in the del statement, which looks a little ugly for me.
Is there something nicer? something like MyClass.getPrivateString('prv')
Of course I can implement one myself, but I would be surprised if there isn't a builtin to surpass this problem.
__machinery__
attributes like__getstate__
. – msw Aug 26 '10 at 20:49__getstate__
are NOT mangled. – Jon-Eric Aug 26 '10 at 20:56__
has something to to with private variables. – John La Rooy Aug 26 '10 at 22:16