Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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; 'newbie': 0.03; 'python.': 0.04; 'mrab': 0.04; 'subject:module': 0.04; 'raises': 0.07; 'subject:object': 0.07; 'python': 0.08; 'be:': 0.09; 'callable.': 0.09; 'message-id:@glegroupsg2000goo.googlegroups.com': 0.09; 'reply-to:addr:comp.lang.python': 0.09; 'to:addr:comp.lang.python': 0.09; 'class,': 0.15; "subject:' ": 0.15; 'forget.': 0.16; 'instantiate': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.16; 'thanks,': 0.18; 'cc:no real name:2**0': 0.20; 'appears': 0.20; 'wrote': 0.20; 'subject:not': 0.21; 'file,': 0.21; 'cc:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'code': 0.25; "i'm": 0.27; 'received:209.85.220': 0.27; 'correct': 0.28; 'import': 0.28; 'fine.': 0.29; 'importing': 0.29; 'module.': 0.29; 'print': 0.29; 'cc:addr:python.org': 0.30; 'module': 0.30; 'imported': 0.30; 'typeerror:': 0.30; 'class': 0.30; 'error': 0.32; 'list': 0.32; 'does': 0.32; "isn't": 0.33; 'there': 0.33; 'however,': 0.34; 'header:User-Agent:1': 0.34; 'file.': 0.34; 'clearly': 0.34; 'like:': 0.34; 'thank': 0.35; 'object': 0.35; 'problem.': 0.36; 'thursday,': 0.37; 'something': 0.37; 'think': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'should': 0.38; 'subject:: ': 0.39; 'either': 0.39; 'recommended': 0.39; 'called': 0.40; "it's": 0.40; 'your': 0.61; '11,': 0.68; 'august': 0.70; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.71; 'reply-to:addr:googlegroups.com': 0.74; 'adopt': 0.84; 'mat': 0.84; 'or:': 0.91; 'resides': 0.91 Newsgroups: comp.lang.python Date: Thu, 11 Aug 2011 17:56:34 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=108.16.47.51; posting-account=21vsegoAAAAdfdSoDHW2LJ4n8gspC-l6 References: User-Agent: G2/1.0 X-Google-Web-Client: true MIME-Version: 1.0 Subject: Re: TypeError: 'module' object is not callable From: Forafo San To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: comp.lang.python@googlegroups.com List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 51 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1313110597 news.xs4all.nl 23970 [2001:888:2000:d::a6]:48669 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:11242 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.