Q:

python: reference "private" variables' names in an organized way

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.

A:

Consider using only a single underscore for private attributes. These are still considered private but do not get name mangled.
class MyClasss(object):
    def __init__(self):
          self._prv=1
    def __getstate__(self):
          ret=self.__dict__.copy()
          del ret['_prv']

A:

At the end, I used a variant of thieger's solution
del ret["_%s__%s" % (MyClasss.__name__, "prv")]

I think this is the most robust way I can write that piece of code, aside from giving up the mangling, which might be the right thing to do, but I was asking what to do in case you actually have mangling :)

