Re: TypeError: 'module object is not callable'



On Sep 3, 10:48 am, christophert...@xxxxxxxxxxx wrote:
Hi

I am new to Python and have recieved this error message when trying to
instantiate an object from a class from another file within the same
directory and wondered what I have done wrong.

I have a Step.py class:
class Step(object)
def __init__(self, sName):
"Initialise a new Step instance"
self.sName = sName
self.depSteps = []
self.remDepSteps = []
self.isCompleted = 0

Then I have created a new file within the same directory called
main.py:

import Step
a = Step("magn")

The following however generates the error
Traceback (most recent call last):
File "main.py", line 3, in ?
a = Step("magn")
TypeError: 'module' object is not callable

This is because when you issue "import Step" you're actually importing
the "Step" _module_, not the "Step" class inside the module.

You can do this in at least two ways:

------
import Step
a = Step.Step("magn") # access the Step class inside Step module
------

or

------
from Step import Step # insert in the current namespace the Step class
a = Step("magn")
------


If anyone could help point me in the right direction, how to fix this
problem it would be much appreciated.
Chris

HTH

.



Relevant Pages

  • Re: Can we create an_object = object() and add attribute like for a class?
    ... Is there any reason that under Python you cannot instantiate the object ... which may make little sense for a namespace). ...
    (comp.lang.python)
  • Re: TypeError: module object is not callable
    ... I am new to Python and have recieved this error message when trying to ... instantiate an object from a class from another file within the same ... If anyone could help point me in the right direction, how to fix this ...
    (comp.lang.python)
  • TypeError: module object is not callable
    ... I am new to Python and have recieved this error message when trying to ... instantiate an object from a class from another file within the same ... If anyone could help point me in the right direction, how to fix this ...
    (comp.lang.python)
  • Re: TypeError: module object is not callable
    ... I am new to Python and have recieved this error message when trying to ... instantiate an object from a class from another file within the same ... The exception is being raised as you are being confused about the ...
    (comp.lang.python)
  • Re: SQL Stored Proc - ASP Page - Return Value
    ... No error message - and yes I am instantiate the recordset: ... "Bob Barrows" wrote in message ...
    (microsoft.public.inetserver.asp.general)