0

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?

3
  • 1
    Have you tried splitting it into more separate steps so see what the uncallable object is? How did you import datetime? Commented May 7, 2015 at 15:02
  • 1
    nice catch!!! on the class module, I just had import Datetime but on the main module I had from datetime import datetime. Changed the class module and it worked. Thanks! Commented May 7, 2015 at 15:05
  • 2
    Incidentally, since you're putting the contents of output_array into a set, why not do it directly? Eg, output_set = set() for property in thingy: output_set.add(property). Also, beware of the dangers of default mutable arguments, although it doesn't matter here since you don't modify query_string in queryCollection(). Commented May 7, 2015 at 15:15

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

from datetime import datetime
Technically, datetime.datetime is a class, not a function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.