Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #30827
| Date | 2012-10-05 10:39 -0700 |
|---|---|
| From | Ethan Furman <ethan@stoneleaf.us> |
| Subject | instance.attribute lookup |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1861.1349459170.27098.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
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
csiph-web