【问题标题】:How can I resolve Python TypeError: 'module' object is not callable?如何解决 Python TypeError:“模块”对象不可调用?
【发布时间】:2012-05-26 19:56:36
【问题描述】:

我正在尝试编写一组 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()

我还导入了所有必需的库

【问题讨论】:

  • 哪一行导致了问题?
  • 你能用整个堆栈跟踪更新问题吗? :) 另外,这个类是否在同一个文件中?

标签: python import module callable


【解决方案1】:

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

self.queryservice=QueryService.QueryService()

【讨论】:

    猜你喜欢
    • 2017-05-08
    • 2020-04-26
    • 2013-12-12
    • 1970-01-01
    • 1970-01-01
    • 2017-06-17
    • 2014-09-21
    • 2011-05-30
    相关资源
    最近更新 更多