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


Groups > comp.lang.python > #30851 > unrolled thread

Re: instance.attribute lookup

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2012-10-05 17:29 -0600
Last post2012-10-05 17:29 -0600
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: instance.attribute lookup Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-05 17:29 -0600

#30851 — Re: instance.attribute lookup

FromIan Kelly <ian.g.kelly@gmail.com>
Date2012-10-05 17:29 -0600
SubjectRe: instance.attribute lookup
Message-ID<mailman.1881.1349479823.27098.python-list@python.org>
On Fri, Oct 5, 2012 at 11:39 AM, Ethan Furman <ethan@stoneleaf.us> wrote:
> There is a StackOverflow question [1] that points to this on-line book [2]
> which has a five-step sequence for looking up attributes:
>
>> When retrieving an attribute from an object (print
>> objectname.attrname) Python follows these steps:
>>
>> 1. If attrname is a special (i.e. Python-provided) attribute for
>> objectname, return it.
>>
>> 2. Check objectname.__class__.__dict__ for attrname. If it exists and
>> is a data-descriptor, return the descriptor result. Search all bases
>> of objectname.__class__ for the same case.
>>
>> 3. Check objectname.__dict__ for attrname, and return if found. If
>> objectname is a class, search its bases too. If it is a class and a
>> descriptor exists in it or its bases, return the descriptor result.
>>
>> 4. Check objectname.__class__.__dict__ for attrname. If it exists and
>> is a non-data descriptor, return the descriptor result. If it exists,
>> and is not a descriptor, just return it. If it exists and is a data
>> descriptor, we shouldn't be here because we would have returned at
>> point 2. Search all bases of objectname.__class__ for same case.
>>
>> 5. Raise AttributeError
>
> I'm thinking step 1 is flat-out wrong and doesn't exist.  Does anybody know
> otherwise?

I think step 1 refers to looking up attributes like "foo.__class__" or
"foo.__dict__" themselves.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web