frame.f_locals['__class__'] -- When does it (not) exist and why?
Chris Angelico
rosuav at gmail.com
Sun Nov 16 00:40:05 EST 2014
On Sun, Nov 16, 2014 at 4:25 PM, <kevinarpe at gmail.com> wrote:
> When super().__init__() is called, a 'magic' local appears in frame.f_locals called '__class__'. Helpfully, it has the correct class for the context, which will differ from type(self). (I discovered this magic local by poking around in the debugger. I am unable to find any official documentation on it.)
>
Interesting. Are you sure you can't get the class name via the
function, rather than depending on this magic local? That seems
fragile.
Your example code isn't currently runnable ("def class"); can you
provide a self-contained program that actually attempts to display
something? It'd be helpful for those of us who aren't familiar with
internal and esoteric details of tracebacks and __init__ :)
ChrisA
More information about the Python-list
mailing list