TypeError: 'module' object is not callable
python at mrabarnett.plus.com
Fri Aug 12 02:22:20 CEST 2011
On 11/08/2011 23:43, Forafo San wrote:
> I wrote a class, Univariate, that resides in a directory that is in my PYTHONPATH. I'm able to import that class into a *.py file. However when I try to instantiate an object with that class like:
> x = Univariate(a) # a is a list that is expected by the Univariate class
> python raises the TypeError: 'module' object is not callable. If I embed the code of the Univariate class in my *.py file, there is no problem. Also, when the class is imported and I do a
> print dir(Univariate)
> it does not print all the methods that are in the class, while if the class code appears in my *.py file, all the methods are available and a list with the correct methods are printed.
> What gives?
I think you mat be confusing the class with the module.
When you write:
you're importing the module.
If the module is called "Univariate" and the class within the module is
called "Univariate" then you should either write:
x = Univariate.Univariate(a) # the class Univariate in the module
from Univariate import Univariate
x = Univariate(a)
Incidentally, it's recommended that module names use lowercase, so that
x = univariate.Univariate(a)
from univariate import Univariate
More information about the Python-list