def get_private_attr(inst, attr):
    'Access private variables without resorting to name mangling'
    s = ('class %(cls)s: \n' +
         ' def _show(self):  return self.%(attr)s \n' +
         'private = %(cls)s._show(inst) \n')
    s %= dict(cls=inst.__class__.__name__, attr=attr)
    d = dict(inst=inst)
    exec(s, d, d)
    return d['private']
Access private variables without resorting to name mangling
recipes/Python/576677_Accessor_functiprivate_variables/recipe-576677.py