5

I know there are several thread regarding this error, but I cant seems to find the right solution for this.

from libcomcat.search import search
import datetime
eventlist = search(starttime = datetime(1945,1,1,0,0),
              endtime = datetime.datetime.now(),
               maxlatitude = -5.747, minlatitude = -11.153,
               maxlongitude = 121.619, minlongitude = 104.7,
              producttype = moment-tensor)

and it return the 'module' object is not callable. I tried to make sure that search is a callable function and not a module by printing it

print (search)

as suggested in TypeError: 'module' object is not callable and returns:

function search at 0x7f4308fe5ea0

What exactly am I missing here? why it seems like search is both a function and a module?

other things I have tried: 1. importing libcomcat as is and calling it as libcomcat.search.search still get the same error 2. someone suggesting to also import it on innit.py inside the parent directory (I dont get why?) still not working

greensquare68
  • 55
  • 1
  • 6
  • It's not `search`. What else are you trying to call? – user2357112 Apr 03 '18 at 01:56
  • The exception tells you which line the problem is one, and also gives you some information about what the problem is. Even if you can't understand all of that, you should definitely paste it into your answer, so that people who _can_ understand it can use it to help debug your problem. Read the [mcve] section in the help for more on what to include in questions. – abarnert Apr 03 '18 at 02:03
  • Problem solved. apparently the problem is on the datetime and all this time i just looking at the wrong problem. – greensquare68 Apr 03 '18 at 02:09

2 Answers2

7

The datetime module contains the datetime class that you are trying to use. To fix this, either import the class from the module:

from datetime import datetime
starttime = datetime(1945,1,1,0,0)

or alternatively, create the datetime object by calling the class from the module:

import datetime
starttime = datetime.datetime(1945,1,1,0,0)
3

The module object that isn't callable here is datetime, in the expression:

datetime(1945,1,1,0,0)

What you probably want is:

datetime.datetime(1945,1,1,0,0)

Alternatively, change import datetime to from datetime import datetime, and change datetime.datetime.now() to datetime.now().