Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

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

like image 698
greensquare68 Avatar asked Apr 03 '18 01:04

greensquare68


People also ask

How do you make a function callable in Python?

How to Make an Object Callable. Simply, you make an object callable by overriding the special method __call__() . __call__(self, arg1, .., argn, *args, **kwargs) : This method is like any other normal method in Python. It also can accept positional and arbitrary arguments.

What does it mean string is not callable in Python?

The result was the TypeError: 'str' object is not callable error. This is happening because we are using a variable name that the compiler already recognizes as something different. To fix this, you can rename the variable to a something that isn't a predefined keyword in Python.

Are Python functions callable?

Python's functions are callable objects So, every function in Python is a callable, meaning it's an object that you're able to call.

What is a module object in Python?

A module is a Python object with arbitrarily named attributes that you can bind and reference. The Python code for a module named aname normally resides in a file named aname.py, as covered in Module Loading. In Python, modules are objects (values) and are handled like other objects.


1 Answers

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)
like image 84
Campbell McDiarmid Avatar answered Sep 28 '22 18:09

Campbell McDiarmid