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


Groups > comp.lang.python > #30851

Re: instance.attribute lookup

Path csiph.com!usenet.pasdenom.info!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed5.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.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'attribute': 0.05; 'case.': 0.05; 'attributes': 0.07; 'class,': 0.07; 'python': 0.09; 'descriptor': 0.09; 'exist.': 0.09; 'exists,': 0.09; 'result.': 0.15; 'attributes:': 0.16; 'attrname': 0.16; 'bases,': 0.16; 'descriptor,': 0.16; 'non-data': 0.16; 'oct': 0.16; 'retrieving': 0.16; 'wrote:': 0.17; 'exists': 0.17; 'refers': 0.17; "shouldn't": 0.17; 'subject:skip:i 10': 0.22; 'raise': 0.24; 'header:In-Reply- To:1': 0.25; '[1]': 0.27; 'am,': 0.27; 'question': 0.27; '[2]': 0.27; 'found.': 0.27; 'message-id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'steps:': 0.29; 'points': 0.29; 'class': 0.29; "i'm": 0.29; 'fri,': 0.30; 'returned': 0.30; 'point': 0.31; 'anybody': 0.32; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'wrong': 0.34; 'sequence': 0.35; 'too.': 0.35; 'received:209.85': 0.35; 'there': 0.35; '(i.e.': 0.36; 'does': 0.37; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'skip:o 20': 0.38; 'to:addr:python.org': 0.39; 'step': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'think': 0.40; 'here': 0.65; 'special': 0.73; '(print': 0.84; 'furman': 0.84; 'to:name:python': 0.84; 'ethan': 0.91
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=JACa5lomp8kDRNkYMEwNHUb95ioDBIDfZwG+HnO/noc=; b=GrF3Uzneu1aGgy+QFhrZS1sjy4l0E0RkyQnjZ3PCENOmXINwOpTVP12HLo6/3hfAdK t541xl0qM5RTDoOZPKxPrgcJC8AtaW6YXTHO2fDnzuvFUqNEbnG9vkNTXVlCxrE89YjP Je/xFQq9kpNUSCcl3wujdO3RvJYZCuqDmDo58mbjodLcJX7WtFO04KG0KZ7A+NcAosaJ oqtvLO/VEgnwPF1YsVX1v/2ucvV+Y4mzhONJFZv1HvyiYgeD+PZbOWgPu+N/dla9odtQ eQ0rjsQ9K1mYp0DJHyG9lo7n7p0oEt4irHMG21n9GqpCUba739dq0V7/Cw0r6NugXaW8 i8Hg==
MIME-Version 1.0
In-Reply-To <506F1B69.8030800@stoneleaf.us>
References <506F1B69.8030800@stoneleaf.us>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Fri, 5 Oct 2012 17:29:51 -0600
Subject Re: instance.attribute lookup
To Python <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
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 <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1881.1349479823.27098.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1349479823 news.xs4all.nl 6865 [2001:888:2000:d::a6]:57566
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:30851

Show key headers only | View raw


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.

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


Thread

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

csiph-web