Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #11236 > unrolled thread
| Started by | Forafo San <ppv.grps@gmail.com> |
|---|---|
| First post | 2011-08-11 15:43 -0700 |
| Last post | 2011-08-11 17:56 -0700 |
| Articles | 6 — 4 participants |
Back to article view | Back to comp.lang.python
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
| From | Forafo San <ppv.grps@gmail.com> |
|---|---|
| Date | 2011-08-11 15:43 -0700 |
| Subject | TypeError: 'module' object is not callable |
| Message-ID | <b5d26e9e-df36-4721-bf1b-d5b60b816fb0@glegroupsg2000goo.googlegroups.com> |
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? Thanks in advance. ====================== FreeBSD 7.2 machine with python version 2.5.6
[toc] | [next] | [standalone]
| From | John Gordon <gordon@panix.com> |
|---|---|
| Date | 2011-08-11 23:39 +0000 |
| Message-ID | <j21p79$b7u$1@reader1.panix.com> |
| In reply to | #11236 |
In <b5d26e9e-df36-4721-bf1b-d5b60b816fb0@glegroupsg2000goo.googlegroups.com> Forafo San <ppv.grps@gmail.com> writes:
> 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
It's difficult to diagnose this problem when you haven't shown us the
code for Univariate.
--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
[toc] | [prev] | [next] | [standalone]
| From | David Robinow <drobinow@gmail.com> |
|---|---|
| Date | 2011-08-11 20:15 -0400 |
| Message-ID | <mailman.2197.1313108141.1164.python-list@python.org> |
| In reply to | #11236 |
On Thu, Aug 11, 2011 at 6:43 PM, Forafo San <ppv.grps@gmail.com> 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: What makes you think you're able to import that class? > 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. It appears that you are importing the "module" Univariate from the file Univariate.py If you want to instantiate the "class" Univariate contained in the "module" Univariate, try x = Univariate.Univariate(a) In the future, please try to include more of your code.
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2011-08-12 01:22 +0100 |
| Message-ID | <mailman.2198.1313108544.1164.python-list@python.org> |
| In reply to | #11236 |
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
[toc] | [prev] | [next] | [standalone]
| From | Forafo San <ppv.grps@gmail.com> |
|---|---|
| Date | 2011-08-11 17:56 -0700 |
| Message-ID | <mailman.2199.1313110597.1164.python-list@python.org> |
| In reply to | #11241 |
On Thursday, August 11, 2011 8:22:20 PM UTC-4, MRAB wrote: > 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 Thank you all for your replies. When I do a from Univariate import Univariate the TypeError disappears and everything is fine. Clearly this was an error that a newbie such as myself is likely to make because of little experience with Python. However, this isn't something I'm likely to forget. I will also adopt the style recommendations. Thanks, again.
[toc] | [prev] | [next] | [standalone]
| From | Forafo San <ppv.grps@gmail.com> |
|---|---|
| Date | 2011-08-11 17:56 -0700 |
| Message-ID | <5effb6ec-7389-4f1d-9707-164227b431e1@glegroupsg2000goo.googlegroups.com> |
| In reply to | #11241 |
On Thursday, August 11, 2011 8:22:20 PM UTC-4, MRAB wrote: > 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 Thank you all for your replies. When I do a from Univariate import Univariate the TypeError disappears and everything is fine. Clearly this was an error that a newbie such as myself is likely to make because of little experience with Python. However, this isn't something I'm likely to forget. I will also adopt the style recommendations. Thanks, again.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web