繁体   English   中英

TypeError:“模块”对象不可调用的python类方法

[英]TypeError: 'module' object is not callable python class method

我有以下类方法:

def queryCollection(self, query_string={}, distinct_output = "_id"):
    output_array = []
    for property in self.coll.find(query_string).distinct(distinct_output):
        output_array.append(property)
    return set(output_array)

def smallDateQuery(self):
    x = self.queryCollection( { "created_at": {"$gte" : datetime(2015, 3, 1), "$lt": datetime(2015, 3, 30)}} )
    return x

当我打电话给第一个时,它起作用:

x = user.queryCollection({ "created_at": {"$gte" : datetime(2015, 3, 1), "$lt": datetime(2015, 3, 30)}})
print len(x)

当我调用第二个时,它不会:

y = user.smallDateQuery()
print len(y)
quit()

我收到以下错误:

 x = self.queryCollection( { "created_at": {"$gte" : datetime(2015, 3, 1), "$lt": datetime(2015, 3, 30)}} )
TypeError: 'module' object is not callable

有什么问题

你可能有

import datetime

在这种情况下,您应该使用

datetime.datetime(2015, 3, 1)

由于datetime是一个模块而出现错误,因此调用的函数是datetime.datetime

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM