python - 解析 json 响应时对象不可调用 python

标签 python

我有一个来自这种格式的 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/

相关文章:

python - 如何创建带有标志修改的 QMessageBox 的子类?

python - 在 Cython 中制作可执行文件

python - 是否可以仅在所有参数运行后才运行拆卸 fixture ?

python - Geodjango - 如何闭合多边形中的孔?

python - numpy 数组中多个元素的索引

python - 带有交互式 SVG 图像的 pyQt

python 列表 : double each element in a list while maintaining the structure

python - 使用 'iloc' 时出现“试图在 DataFrame 的切片副本上设置值”错误

python - 如果未检测到任何更改,如何防止 alembic revision --autogenerate 制作修订文件?

python - 在具有两个输出的模型中使用自定义 keras 层创建时出错