TypeError: 'module' object is not callable

Jason Swails jason.swails at gmail.com
Thu Aug 11 21:47:57 EDT 2011


On Thu, Aug 11, 2011 at 8:56 PM, Forafo San <ppv.grps at gmail.com> wrote:

>
> 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.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

As a beginner, I found that it was useful to note how these 2 approaches
differ.  In the first approach:

import Univariate
a = Univariate.Univariate(foo)

what you're doing is loading everything in Univariate in a separate
namespace (the Univariate namespace).  The other approach:

from Univariate import Univariate
a = Univariate(foo)

what you're doing is loading *just* Univariate into your top level
namespace.  It's important to note this difference because it has
potentially critical implications as far as clobbering existing functions
that happen to have the same name (if you're loading into your top level
namespace with, for instance, "from mymodule import *") versus keeping
everything in a separate namespace so stuff doesn't get overwritten.

This is more applicable to scripts/programs you write that import a number
of different modules, all of whom may contain objects with the same name.

All the best,
Jason

-- 
Jason M. Swails
Quantum Theory Project,
University of Florida
Ph.D. Candidate
352-392-4032
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110811/f2a1097f/attachment-0001.html>


More information about the Python-list mailing list