__bases__ misleading error message
Terry Reedy
tjreedy at udel.edu
Sat Jan 24 16:58:10 EST 2015
On 1/24/2015 4:14 PM, Mario Figueiredo wrote:
> In article <54c39366$0$13006$c3e8da3$5496439d at news.astraweb.com>,
> steve+comp.lang.python at 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: How does Python maps names to memory
> addresses in the interpreter?
Python the language maps names to objects that have identity, type, and
value. The CPython implementation does the mapping with a hash table
and C pointers (to computer memory addresses), but addresses are not
part of the language definition. Neuroscientists still puzzle over how
we do such mapping.
> "__main__"
> from module import a_name
A module is a namespace associating names with objects. This statememt
says to import the a_name to object association from module and add it
to __main__
> y = a_name + 1
This statement uses the imported association in __main__ to access the
object and add 1, and bind 'y' to the resulting object.
--
Terry Jan Reedy
More information about the Python-list
mailing list