Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #11241
| Date | 2011-08-12 01:22 +0100 |
|---|---|
| From | MRAB <python@mrabarnett.plus.com> |
| Subject | Re: TypeError: 'module' object is not callable |
| References | <b5d26e9e-df36-4721-bf1b-d5b60b816fb0@glegroupsg2000goo.googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2198.1313108544.1164.python-list@python.org> (permalink) |
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:
import Univariate
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:
import Univariate
x = Univariate.Univariate(a) # the class Univariate in the module
Univariate
or:
from Univariate import Univariate
x = Univariate(a)
Incidentally, it's recommended that module names use lowercase, so that
would be:
import univariate
x = univariate.Univariate(a)
or:
from univariate import Univariate
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
TypeError: 'module' object is not callable Forafo San <ppv.grps@gmail.com> - 2011-08-11 15:43 -0700
Re: TypeError: 'module' object is not callable John Gordon <gordon@panix.com> - 2011-08-11 23:39 +0000
Re: TypeError: 'module' object is not callable David Robinow <drobinow@gmail.com> - 2011-08-11 20:15 -0400
Re: TypeError: 'module' object is not callable MRAB <python@mrabarnett.plus.com> - 2011-08-12 01:22 +0100
Re: TypeError: 'module' object is not callable Forafo San <ppv.grps@gmail.com> - 2011-08-11 17:56 -0700
Re: TypeError: 'module' object is not callable Forafo San <ppv.grps@gmail.com> - 2011-08-11 17:56 -0700
csiph-web