Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > instance.attribute lookup

Reply
Thread Tools

instance.attribute lookup

 
 
Ethan Furman
Guest
Posts: n/a
 
      10-05-2012
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...s/ch01s05.html
 
Reply With Quote
 
 
 
 
Steven D'Aprano
Guest
Posts: n/a
 
      10-05-2012
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
 
Reply With Quote
 
 
 
 
Ethan Furman
Guest
Posts: n/a
 
      10-05-2012
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~
 
Reply With Quote
 
Mark Lawrence
Guest
Posts: n/a
 
      10-05-2012
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can you tell a Cisco router NOT to cache a DNS lookup? Terra Dactyl Cisco 5 01-07-2005 04:37 AM
Domain Lookup Fred Atkinson Cisco 4 11-16-2004 03:24 PM
No Lookup Fred Atkinson Cisco 2 10-30-2004 02:23 PM
Re: Lookup SSID Paul E Wireless Networking 0 09-01-2004 05:37 PM
string condition file - lookup logic jason@cyberpine.com Perl 0 08-10-2004 07:28 PM



Advertisments