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


Groups > comp.lang.python > #84496

Re: __bases__ misleading error message

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:error': 0.03; 'interpreter': 0.05; 'attribute': 0.07; 'compiler': 0.07; 'indices': 0.07; 'variables': 0.07; 'sub': 0.09; 'python': 0.11; 'jan': 0.12; 'stored': 0.12; '24,': 0.16; 'code?': 0.16; 'dict': 0.16; 'globals': 0.16; 'imports': 0.16; "module's": 0.16; 'says...': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'looked': 0.18; 'variable': 0.18; 'module': 0.19; 'stack': 0.19; '>>>': 0.22; 'memory': 0.22; 'import': 0.22; 'error': 0.23; 'module,': 0.24; 'pointer': 0.24; 'looks': 0.24; 'second': 0.26; 'header:In-Reply- To:1': 0.27; 'correct': 0.29; 'array': 0.29; "doesn't": 0.30; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'url:wiki': 0.31; 'location,': 0.31; 'object.': 0.31; 'question:': 0.31; 'url:wikipedia': 0.31; 'handled': 0.32; 'addresses': 0.33; 'could': 0.34; 'message.': 0.35; 'display': 0.35; 'no,': 0.35; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'thanks': 0.36; 'url:org': 0.36; 'level': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'how': 0.40; 'skip:u 10': 0.60; "you're": 0.61; 'first': 0.61; 'name': 0.63; 'map': 0.64; 'article': 0.77; "'foo'": 0.84; '2015': 0.84; 'dict,': 0.84; 'dict.': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=7pu+XGrSWo/z6pxHsYzJqwEX3PXWZZA5YjnQLZmkMAQ=; b=jL/IUV3x0PC+bn4eFozw45VNQc7BbxaoQXb1hqW0qlc/6k06CB81mzZEKMyquo/kJp KA3qW2b9+OaxpLDIL/skDufFD8k+0Inx8RO/RIRxJiKmgR8LlKyht9jIAbkpoJODPqZN UN9WFLg0p7INajuCjHE4pUkY9hfxz0qv+Z5D3smkvG0wVgd6IFWDyzZ5tpWGU+rScJ7j 7LW/iM/yQ4mJH3mDSGsdWYz7myAq+lHCfxEuMfEvAJpXegOjZBVIsUPsieCbD1uzolZD yq4Lwa/Sp+Z4rLwq0grcxbegzHscQSwFL70Uqh+sT6jhysSfVU6z8fDnKlYp3XBEqXLo 8rKQ==
X-Received by 10.66.157.5 with SMTP id wi5mr22052776pab.37.1422135972493; Sat, 24 Jan 2015 13:46:12 -0800 (PST)
MIME-Version 1.0
In-Reply-To <MPG.2f2e298c14dbed69989692@nntp.aioe.org>
References <1a194e0a0b738d205de54180fa7@nntp.aioe.org> <54c39366$0$13006$c3e8da3$5496439d@news.astraweb.com> <MPG.2f2e298c14dbed69989692@nntp.aioe.org>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Sat, 24 Jan 2015 14:45:32 -0700
Subject Re: __bases__ misleading error message
To Python <python-list@python.org>
Content-Type text/plain; charset=UTF-8
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.18099.1422135976.18130.python-list@python.org> (permalink)
Lines 46
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1422135976 news.xs4all.nl 2863 [2001:888:2000:d::a6]:52437
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:84496

Show key headers only | View raw


On Sat, Jan 24, 2015 at 2:14 PM, Mario Figueiredo <marfig@gmail.com> wrote:
> In article <54c39366$0$13006$c3e8da3$5496439d@news.astraweb.com>,
> steve+comp.lang.python@pearwood.info says...
>> >         AttributeError: 'Sub' instance has no attribute '__bases__',
>> >         AttributeError: 'foo' object has no attribute '__bases__'
>>
>> The first would be nice. The second is impossible: objects may have no name,
>> one name, or many names, and they do not know what names they are bound to.
>> So the Sub instance bound to the name 'foo' doesn't know that its name
>> is 'foo', so it cannot display it in the error message.
>
> Thanks for the information! :)
>
> But that begs the OT question:

No, it doesnt. http://en.wikipedia.org/wiki/Begging_the_question

> How does Python maps names to memory
> addresses in the interpreter?

Global variables are looked up in the current stack frame's globals dict.

>>> a = 1
>>> b = 2
>>> globals()['a']
1
>>> globals()['b']
2

Local variables of functions could be handled the same way, but for
efficiency the compiler instead maps the names to indices of a local
variable array associated with the stack frame. Either way, at the C
level the value stored in the dict or array is a pointer to the memory
location of the object.

>     "__main__"
>     from module import a_name
>     y = a_name + 1
>
> How does python interpreter know how to map 'name' to the correct memory
> location, if this __main__ code is only ran after 'module' code?

I'm not sure I'm understanding what you're asking, but the import
statement imports the module, looks up "a_name" in that module's
globals dict, and binds the same object to a_name in the current
module's globals dict.

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


Thread

__bases__ misleading error message Mario Figueiredo <marfig@gmail.com> - 2015-01-24 10:16 +0000
  Re: __bases__ misleading error message Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-24 23:43 +1100
    Re: __bases__ misleading error message Mario Figueiredo <marfig@gmail.com> - 2015-01-24 22:14 +0100
      Re: __bases__ misleading error message Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-24 14:45 -0700
        Re: __bases__ misleading error message Mario Figueiredo <marfig@gmail.com> - 2015-01-24 23:09 +0100
          Re: __bases__ misleading error message Chris Angelico <rosuav@gmail.com> - 2015-01-25 09:25 +1100
            Re: __bases__ misleading error message Mario Figueiredo <marfig@gmail.com> - 2015-01-24 23:33 +0100
              Re: __bases__ misleading error message Chris Angelico <rosuav@gmail.com> - 2015-01-25 09:37 +1100
                Re: __bases__ misleading error message Mario Figueiredo <marfig@gmail.com> - 2015-01-24 23:59 +0100
      Re: __bases__ misleading error message Terry Reedy <tjreedy@udel.edu> - 2015-01-24 16:58 -0500
        Re: __bases__ misleading error message Mario Figueiredo <marfig@gmail.com> - 2015-01-24 23:02 +0100
          Re: __bases__ misleading error message Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-24 15:16 -0700
            Re: __bases__ misleading error message Mario Figueiredo <marfig@gmail.com> - 2015-01-24 23:36 +0100
      Re: __bases__ misleading error message Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-25 14:18 +1100
        Re: __bases__ misleading error message Mario Figueiredo <marfig@gmail.com> - 2015-01-25 12:07 +0100
          Re: __bases__ misleading error message Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-25 23:00 +1100
            Re: __bases__ misleading error message Mario Figueiredo <marfig@gmail.com> - 2015-01-25 13:49 +0100
              Re: __bases__ misleading error message Marko Rauhamaa <marko@pacujo.net> - 2015-01-25 14:53 +0200
            Re: __bases__ misleading error message Terry Reedy <tjreedy@udel.edu> - 2015-01-25 16:35 -0500
            Re: __bases__ misleading error message Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-25 19:21 -0700
    Re: __bases__ misleading error message Marco Buttu <marco.buttu@gmail.com> - 2015-01-24 23:09 +0100
    Re: __bases__ misleading error message Marco Buttu <marco.buttu@gmail.com> - 2015-01-24 15:12 +0100
  Re: __bases__ misleading error message Terry Reedy <tjreedy@udel.edu> - 2015-01-24 14:24 -0500
    Re: __bases__ misleading error message Mario Figueiredo <marfig@gmail.com> - 2015-01-24 22:03 +0100
    Re: __bases__ misleading error message Marco Buttu <marco.buttu@gmail.com> - 2015-01-24 22:51 +0100
      Re: __bases__ misleading error message Terry Reedy <tjreedy@udel.edu> - 2015-01-24 19:55 -0500
        Re: __bases__ misleading error message Marco Buttu <marco.buttu@gmail.com> - 2015-01-25 11:30 +0100
    Re: __bases__ misleading error message Marco Buttu <marco.buttu@gmail.com> - 2015-01-24 22:51 +0100

csiph-web