【发布时间】:2017-04-06 05:59:27
【问题描述】:
我在 python 中有一个对象 myobj(MyObj 的一个实例),当使用 print() 调用时,它会打印出来
{"host": "localhost", "user_indices": [], "password": null, "port": 27017}
所以myobj 似乎是一个字典样式的对象。但是myobj['host'] 提出了
TypeError: 'AutoProxy[MyObj]' object has no attribute '__getitem__'
我在尝试myobj.host 时收到AttributeError。
我也尝试过使用myobj.__dict__['host'] 和dict(myobj)['host'] 无济于事。有没有人遇到过这个问题?
【问题讨论】:
-
你在这里使用什么 Python 模块?
-
这些方法之一是否在
MyObj类或其超类中被覆盖:__repr__或__str__或__unicode__?
标签: python oop object dictionary attributes