Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #11241

Re: TypeError: 'module' object is not callable

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:module': 0.04; 'raises': 0.07; 'subject:object': 0.07; 'python': 0.08; 'be:': 0.09; 'callable.': 0.09; 'from:addr:python': 0.09; 'class,': 0.15; "subject:' ": 0.15; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'instantiate': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'reply-to:addr :python-list': 0.16; 'wrote:': 0.16; 'appears': 0.20; 'wrote': 0.20; 'subject:not': 0.21; 'file,': 0.21; 'header:In-Reply-To:1': 0.22; 'code': 0.25; "i'm": 0.27; 'received:84': 0.28; 'correct': 0.28; 'import': 0.28; 'importing': 0.29; 'module.': 0.29; 'print': 0.29; 'module': 0.30; 'imported': 0.30; 'typeerror:': 0.30; 'class': 0.30; 'list': 0.32; 'does': 0.32; 'there': 0.33; 'to:addr :python-list': 0.33; 'header:User-Agent:1': 0.34; 'file.': 0.34; 'like:': 0.34; 'reply-to:addr:python.org': 0.34; 'object': 0.35; 'problem.': 0.36; 'think': 0.38; 'should': 0.38; 'subject:: ': 0.39; 'either': 0.39; 'recommended': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; "it's": 0.40; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.71; 'mat': 0.84; 'or:': 0.91; 'resides': 0.91
X-IronPort-Anti-Spam-Filtered true
X-IronPort-Anti-Spam-Result AowHAJBxRE5UXebj/2dsb2JhbABBmFWPCXeBQAEBBThAEQsIEAkWDwkDAgECAQ04EwgBAYdtuS6GRwSLXUmLdItl
Date Fri, 12 Aug 2011 01:22:20 +0100
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20110624 Thunderbird/5.0
MIME-Version 1.0
To python-list@python.org
Subject Re: TypeError: 'module' object is not callable
References <b5d26e9e-df36-4721-bf1b-d5b60b816fb0@glegroupsg2000goo.googlegroups.com>
In-Reply-To <b5d26e9e-df36-4721-bf1b-d5b60b816fb0@glegroupsg2000goo.googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To python-list@python.org
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2198.1313108544.1164.python-list@python.org> (permalink)
Lines 42
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1313108544 news.xs4all.nl 23958 [2001:888:2000:d::a6]:47453
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:11241

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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