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: 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 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: In-Reply-To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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