一个object是不能像dict那样通过[]访问的,比如下面这段代码会报错:
>>> class Foo():
... id = 1
...
>>>
>>> f = Foo()
>>> f[id]
Traceback (most recent call last):File "<stdin>", line 1, in <module>
AttributeError: Foo instance has no attribute '__getitem__'
正确的做法是通过getattr(obj, name)