简体   繁体   中英

TypeError: 'module' object is not callable python class method

I have the following class methods:

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

When I call the first one, it works:

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

When I call the second, it does not:

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

I get the following error:

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

What is the issue?

You probably have

import datetime

in which case you should use

datetime.datetime(2015, 3, 1)

The error arises because datetime is a module, the function to call is datetime.datetime .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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