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?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:not': 0.03; '16,': 0.03; '__init__': 0.09; 'function,': 0.09; 'subject:skip:f 10': 0.09; 'cc:addr:python-list': 0.11; '4:25': 0.16; 'called,': 0.16; 'debugger.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'magic': 0.16; 'wrote:': 0.18; 'differ': 0.19; 'seems': 0.21; 'appears': 0.22; 'example': 0.22; 'cc:addr:python.org': 0.22; "aren't": 0.24; 'helpful': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'correct': 0.29; 'subject:) ': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'context,': 0.31; 'class': 0.32; 'subject: (': 0.35; "can't": 0.35; 'display': 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'nov': 0.38; 'pm,': 0.38; 'rather': 0.38; 'sure': 0.39; 'unable': 0.39; 'called': 0.40; 'name': 0.63; 'provide': 0.64; 'details': 0.65; 'discovered': 0.83; "it'd": 0.84; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type:content-transfer-encoding; bh=zeDxs2bMCEEUJiIzaWo1sYllcPHJxaiBusy9ah+4X0s=; b=qOBuzFRg6Me3rZqBeAa5DxiPfBK1x1gilPHbBZWgYN2uuXds3ndqLlxcQPzQBCirr8 CKDisuRKwuVORcaPFPMZmMBqoL9nNEPpn1+aeoRYTkXOk6J4MopnCtUuLW7TX/0Yy3i/ E2meWb4hCIY2EmWXBnHRuBvEIWaiwfGZiOWABU/LeWCqXdtV9yjGeNQAPVwvU7yd5vSH bSHgit/y8+HAbmMfetSfypij+dmKkgJKIdYuDLrnGb1uYgU1kp9HvE9AVWBu9A0Ywiof OMtKZ/cJZSgK2S4GlVVgCLHfc49sy/jkvTImpjJhNlV6EjSwYshB3OjP102/0ePDoOfc iLnw==
MIME-Version 1.0
X-Received by 10.50.61.140 with SMTP id p12mr12074596igr.34.1416116405868; Sat, 15 Nov 2014 21:40:05 -0800 (PST)
In-Reply-To <c1287648-21e0-457b-ac41-010642a41e9c@googlegroups.com>
References <c1287648-21e0-457b-ac41-010642a41e9c@googlegroups.com>
Date Sun, 16 Nov 2014 16:40:05 +1100
Subject Re: frame.f_locals['__class__'] -- When does it (not) exist and why?
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15870.1416116415.18130.python-list@python.org> (permalink)
Lines 18
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1416116415 news.xs4all.nl 2848 [2001:888:2000:d::a6]:35813
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:80856

Show key headers only | 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