using __getitem()__ correctly
Steven D'Aprano
steve at pearwood.info
Wed Dec 30 18:50:53 EST 2015
On Thu, 31 Dec 2015 10:13 am, Ben Finney wrote:
> You may be familiar with other languages where the distinction between
> “attribute of an object” is not distinct from “item in a dictionary”.
> Python is not one of those languages; the distinction is real and
> important.
I'm not sure what distinction you're referring to, can you explain?
Obviously there is a syntax difference between x.attr and x['key'], but
attributes *are* items in a dictionary (ignoring __slots__ and __getattr__
for the time being). Either the instance __dict__, the class __dict__, or a
superclass __dict__.
--
Steven
More information about the Python-list
mailing list