我有一个来自这种格式的 URL 的响应。
'history': {'all': [[u'09 Aug', 1,5'],[u'16 Aug', 2, 6]]}
代码是:
response = urllib.urlopen(url)
data = json.loads(response.read())
print data["fixture_history"]['all']
customObject = MyObject (
history = data["history"]['all']
)
打印有效,但在我的自定义类中我看到此错误:
history = data["history"]['all']
TypeError: 'module' object is not callable
我的类(class)是:
class MyObject:
#init
def _init_(self,history):
self.hstory = history
最佳答案
Printing works but in my custom class I am seeing this error : TypeError: 'module' object is not callable
我打赌你的类是在名为 MyObject.py
的模块中定义的,并且你将其导入为 import MyObject
而不是 from MyObject import MyObject
,因此在您的调用代码中,名称 MyObject
绑定(bind)到模块,而不是类。
关于python - 解析 json 响应时对象不可调用 python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34513010/