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


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

instance.attribute lookup

Started byEthan Furman <ethan@stoneleaf.us>
First post2012-10-05 10:39 -0700
Last post2012-10-06 00:32 +0100
Articles 4 — 3 participants

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


Contents

  instance.attribute lookup Ethan Furman <ethan@stoneleaf.us> - 2012-10-05 10:39 -0700
    Re: instance.attribute lookup Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-05 23:00 +0000
      Re: instance.attribute lookup Ethan Furman <ethan@stoneleaf.us> - 2012-10-05 16:12 -0700
      Re: instance.attribute lookup Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-10-06 00:32 +0100

#30827 — instance.attribute lookup

FromEthan Furman <ethan@stoneleaf.us>
Date2012-10-05 10:39 -0700
Subjectinstance.attribute lookup
Message-ID<mailman.1861.1349459170.27098.python-list@python.org>
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?

~Ethan~

[1]
http://stackoverflow.com/q/10536539/208880

[2]
http://www.cafepy.com/article/python_attributes_and_methods/ch01s05.html

[toc] | [next] | [standalone]


#30847

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2012-10-05 23:00 +0000
Message-ID<506f668d$0$29978$c3e8da3$5496439d@news.astraweb.com>
In reply to#30827
On Fri, 05 Oct 2012 10:39:53 -0700, Ethan Furman 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.
[...]
> I'm thinking step 1 is flat-out wrong and doesn't exist.  Does anybody
> know otherwise?

I'm thinking I don't even understand what step 1 means.

What's a Python-provided attribute, and how is it different from other 
attributes?



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#30848

FromEthan Furman <ethan@stoneleaf.us>
Date2012-10-05 16:12 -0700
Message-ID<mailman.1878.1349479270.27098.python-list@python.org>
In reply to#30847
Steven D'Aprano wrote:
> On Fri, 05 Oct 2012 10:39:53 -0700, Ethan Furman 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.
> [...]
>> I'm thinking step 1 is flat-out wrong and doesn't exist.  Does anybody
>> know otherwise?
> 
> I'm thinking I don't even understand what step 1 means.
> 
> What's a Python-provided attribute, and how is it different from other 
> attributes?

Well, if /you/ don't understand it I feel a lot better about not 
understanding it either!  :)

Glad to know I'm not missing something (besides ESP, a crystal ball, and 
a mind-reader!)

~Ethan~

[toc] | [prev] | [next] | [standalone]


#30853

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2012-10-06 00:32 +0100
Message-ID<mailman.1883.1349479927.27098.python-list@python.org>
In reply to#30847
On 06/10/2012 00:12, Ethan Furman wrote:
> Steven D'Aprano wrote:
>> On Fri, 05 Oct 2012 10:39:53 -0700, Ethan Furman 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.
>> [...]
>>> I'm thinking step 1 is flat-out wrong and doesn't exist.  Does anybody
>>> know otherwise?
>>
>> I'm thinking I don't even understand what step 1 means.
>>
>> What's a Python-provided attribute, and how is it different from other
>> attributes?
>
> Well, if /you/ don't understand it I feel a lot better about not
> understanding it either!  :)
>
> Glad to know I'm not missing something (besides ESP, a crystal ball, and
> a mind-reader!)
>
> ~Ethan~

My probably highly uneducated guess is that "Python-provided attribute" 
refers to double underscore names. YMMV by several trillion light years :)

-- 
Cheers.

Mark Lawrence.

[toc] | [prev] | [standalone]


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


csiph-web