简体   繁体   中英

python 'module' object is not callable when calling a function

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

I think the issue you have is to do with the datetime function. The module datetime has a function called datetime that you are trying to use. Either change

import datetime

to

from datetime import datetime

or call the function by using datetime.datetime()

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() .

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