Square bracket and dot notations?

Asen Bozhilov asen.bozhilov at gmail.com
Sat Jun 11 05:41:36 EDT 2011


Hi all,
I am beginner in Python. What is interesting for me is that Python
interpreter treats in different way dot and square bracket notations.
I am coming from JavaScript where both notations lead prototype chain
lookup.

In Python it seems square bracket and dot notations lead lookup in
different "store".

Simple example with dict object:

d = {"key" : "value"}

print d["key"] #value

print d.key #AttributeError

I found an implementation of dict which uses both notations for its
keys lookup, which I think is stupid idea when obviously both
notations lead different lookup. It will confuse me as a reader of the
code.

Anyway, I would like to know more about the lookup for key of dict and
lookup for property of any object with dot notation. Any materials and
explanations are highly appreciated.



More information about the Python-list mailing list