It's related to the name mangling, see the documentation:
Notice that code passed to exec() or eval() does not consider the
classname of the invoking class to be the current class; this is
similar to the effect of the global statement, the effect of which is
likewise restricted to code that is byte-compiled together. The same restriction applies to getattr(), setattr() and delattr(), as well as when referencing __dict__
directly.
So, to properly use a private variable in eval()
, it has to be passed in a mangled form, e.g. print(eval('_A__private + 2'))