python - 如何解决 Python 类型错误 : 'module' object is not callable?

标签 python import module callable

我正在尝试编写一组 Python 类,这些类将查询数据库以检索一些值,然后构建一个网络图。问题是每当我尝试调用我的类之一的构造函数时,我都会收到此错误 相关代码如下

class NetworkConstructor:  
def __init__(self):
    self.nodes=dict()
    self.queryservice=QueryService()
    self.graph=networkx.Graph()

QueryService 类的相关位是

def __init__(self):
    self.connect()

def connect(self):
    self.conn=MySQLdb.Connect(host="xxx", port=3306,user="xxx",passwd="xxx",db="xxx")
    self.cursor=self.conn.cursor()

我也导入了所有必需的库

最佳答案

看起来您的 QueryService 类位于同名的模块中。尝试一下

self.queryservice=QueryService.QueryService()

关于python - 如何解决 Python 类型错误 : 'module' object is not callable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10666233/

相关文章:

mysql - 如何在每次更新后转储 MySql 数据库?

Linux 内核模块——安全风险?

python - Pandas :用另一个数据框替换一行

python - 如何在私有(private)子网上运行Dataflow python?

python /Django : How to detect and avoid import name conflict?

ruby-on-rails - CSV 导入问题

ruby - 点运算符与范围解析运算符与 Ruby 中的模块

node.js - 认真调试node.js 'Cannot find module xyz/abcd'

python - 拆分一个太大的类

python - 多边形 Blob 的中心线(二值图像)