Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80856

Re: frame.f_locals['__class__'] -- When does it (not) exist and why?

References <c1287648-21e0-457b-ac41-010642a41e9c@googlegroups.com>
Date 2014-11-16 16:40 +1100
Subject Re: frame.f_locals['__class__'] -- When does it (not) exist and why?
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.15870.1416116415.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, Nov 16, 2014 at 4:25 PM,  <kevinarpe@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

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

frame.f_locals['__class__'] -- When does it (not) exist and why? kevinarpe@gmail.com - 2014-11-15 21:25 -0800
  Re: frame.f_locals['__class__'] -- When does it (not) exist and why? Chris Angelico <rosuav@gmail.com> - 2014-11-16 16:40 +1100
    Re: frame.f_locals['__class__'] -- When does it (not) exist and why? kevinarpe@gmail.com - 2014-11-15 22:28 -0800

csiph-web