473,854 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TypeError: 'module object is not callable'

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.remDepStep s = []
self.isComplete d = 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

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

Sep 3 '07
33 56524
ch************* @hotmail.com wrote:
Thank you for your help that seems to have done the trick.
You are correct Diez B. Roggisch that I come from a java background!

I have a new tiny problem I can't understand either.
Withing Step.py I have the following method

def isCompleted(sel f):
"Check whether data step has been processed"
return self.isComplete d

Then within main.py I simply wish to print the value of isCompleted
which I try to do by the following
print 'Magn completed status is',a.isComplet ed()

Which returns the following error:
a.isCompleted()
TypeError: 'int' object is not callable

I have tried ideas such as int(a.isComplet ed) but to no prevail. Any
ideas?
The others spottet the error I missed. But I can offer something else:

http://dirtsimple.org/2004/12/python-is-not-java.html

It's a worthy read for someone coming from Java, needing time to adjust.

Diez
Sep 3 '07 #11
>
The others spottet the error I missed. But I can offer something else:

http://dirtsimple.org/2004/12/python-is-not-java.html

It's a worthy read for someone coming from Java, needing time to adjust.

Diez- Hide quoted text -

- Show quoted text -
That deffinately was a useful read, thanks.
Thankyou to everyone who sorted these problems for me, I have
progressed very well
with this python program throughout the day now.

I have another little question before I finish today:
I am currently struggling to use a global variable in my static
functions. I'll explain further

Within my main.py file I have

class Main(object):
stepStore = StepStore()

@staticmethod
def createDepSteps( ):
....
stepStore.addSt ep([bol7, pre5])
.......

@staticmethod
def processSteps():
for step in stepStore.stepL ist[:]:
......

Main.createDepS teps()
Main.processSte ps()
Trying this approach I am getting a error saying with the
processSteps() method, stepStore is undefined
To solve this problem I am currently passing in the processSteps()
parameter a stepStore instance created within createDepSteps( )
but there is surely a way stepStore can be a global attribute which
can be accessed from both methods?
Any help would be much appreciated again
Cheers
Chris

Sep 3 '07 #12
On Mon, 03 Sep 2007 16:13:28 +0000, christophertidy wrote:
Within my main.py file I have

class Main(object):
stepStore = StepStore()

@staticmethod
def createDepSteps( ):
....
stepStore.addSt ep([bol7, pre5])
.......

@staticmethod
def processSteps():
for step in stepStore.stepL ist[:]:
......

Main.createDepS teps()
Main.processSte ps()

What's `Main` useful for? Is Java shining through again? A class with
just static methods isn't a class but just a container for functions. But
functions usually live in modules in Python so get rid of that class and
move the functions to module level.
Trying this approach I am getting a error saying with the
processSteps() method, stepStore is undefined
`stepStore` is searched in the function and then in the module. But it
is defined in the class. So you have to access `Main.stepStore `. Unless
you are modifying `stepStore.step List` while iterating over it, you don't
need to make a copy by the way.

Ciao,
Marc 'BlackJack' Rintsch
Sep 3 '07 #13
ch************* @hotmail.com wrote:
>
>>
The others spottet the error I missed. But I can offer something else:

http://dirtsimple.org/2004/12/python-is-not-java.html

It's a worthy read for someone coming from Java, needing time to adjust.

Diez- Hide quoted text -

- Show quoted text -

That deffinately was a useful read, thanks.
Thankyou to everyone who sorted these problems for me, I have
progressed very well
with this python program throughout the day now.

I have another little question before I finish today:
I am currently struggling to use a global variable in my static
functions. I'll explain further

Within my main.py file I have

class Main(object):
stepStore = StepStore()

@staticmethod
def createDepSteps( ):
....
stepStore.addSt ep([bol7, pre5])
.......

@staticmethod
def processSteps():
for step in stepStore.stepL ist[:]:
......

Main.createDepS teps()
Main.processSte ps()
Trying this approach I am getting a error saying with the
processSteps() method, stepStore is undefined
To solve this problem I am currently passing in the processSteps()
parameter a stepStore instance created within createDepSteps( )
but there is surely a way stepStore can be a global attribute which
can be accessed from both methods?
Any help would be much appreciated again
You are deeeeep down in javaland again. first of all, with the exception of
factory methods, staticmethods or classmethods usually aren't needed. In
Python, you can define functions directly.

So move the above methods "toplevel", aka out of the class-context. and just
make stepStore a module-global variable.

Then things should work.

The distinction between staticmethod and classmethod is, that staticmethod
is a "pure" method, something unknown in Java.

the classmethod OTOH is a method that gets the class as first argument
(instead of the instance, as in an instance-method):

class Foo(object):
@classmethod
def bar(cls):
print cls

However: get rid of unnecessary classes. Java is severely limited regarding
the definition of "pure" code, the permanently needed class-context for
e.g. a main-method is absurd - to say the least.

Diez
Sep 3 '07 #14
ch************* @hotmail.com a écrit :
(snip)
>
I have another little question before I finish today:
I am currently struggling to use a global variable in my static
functions. I'll explain further

Within my main.py file I have

class Main(object):
stepStore = StepStore()

@staticmethod
def createDepSteps( ):
....
stepStore.addSt ep([bol7, pre5])
.......

@staticmethod
def processSteps():
for step in stepStore.stepL ist[:]:
......

Main.createDepS teps()
Main.processSte ps()
(snip)

Marc and Diez already gave you the good answers on this (basically: get
rid of useless classes, and use plain functions instead of
staticmethods). I'd just add a couple comments:

First point: OO is not about classes, it's about objects - FWIW, the
mere concept of 'class' is nowhere in the definition of OO, and some
OOPLs don't even have that concept (cf Self and Javascript).

Second point : in Python, everything (well... almost - at least
everything that can be bound to a name) is an object. So Python's
modules and functions are objects.

Third point : "top-level" (aka 'module level', aka 'globals') names
(names defined outside classes or functions) are in fact module
attributes. So, to make a long story short, you can consider a module as
a kind of a singleton.

What I wanted to point out here is that there's much more to OO than
what one learns with Java - and, FWIW, much more to Python's object
model than what it may seems at first.

Ah, and, BTW : welcome here !-)
Sep 3 '07 #15
Thanks guys. Changing to how Python does things has a lot of geting
used to!
Do any of you have any ideas on the best way to do the following
problem:

Each loop I perform, I get a new list of Strings.
I then want to print these lists as columns adjacent to each other
starting with the first
created list in the first column and last created list in the final
column.

If you need any more information, just let me know!
Cheers

Sep 4 '07 #16
On 9/4/07, Ch********@jet. uk <Ch********@jet .ukwrote:
Thanks guys. Changing to how Python does things has a lot of geting
used to!
Do any of you have any ideas on the best way to do the following
problem:

Each loop I perform, I get a new list of Strings.
I then want to print these lists as columns adjacent to each other
starting with the first
created list in the first column and last created list in the final
column.

If you need any more information, just let me know!
Cheers
If I understand correctly what you may want is:
>>l = ['1', '2', '3', '4']
you can do:
>>print "\t".join(l ) # lookup join method in string module,
assuming "\t" as the delimiter

or,
>>for i in l:
..... print i, '\t' , # note the trailing ","

If this is not what you want, post an example.

Btw, Please post new issues in a separate thread.

Cheers,
--
----
Amit Khemka
website: www.onyomo.com
wap-site: www.owap.in
Sep 4 '07 #17
On 2007-09-04, Ch********@jet. uk <Ch********@jet .ukwrote:
Thanks guys. Changing to how Python does things has a lot of geting
used to!
That's part of the fun :-)
Do any of you have any ideas on the best way to do the following
problem:

Each loop I perform, I get a new list of Strings.
I then want to print these lists as columns adjacent to each other
starting with the first
created list in the first column and last created list in the final
column.
Use zip:
>>x = ['1', '2']
y = ['3', '4']
for row in zip(x,y):
.... print ', '.join(row)
....
1, 3
2, 4
zip() constructs a list of rows, like

[('1', '3'), ('2', '4')]

which is then quite easy to print

Good luck,
Albert
Sep 4 '07 #18
On Sep 4, 11:24 am, "Amit Khemka" <khemkaa...@gma il.comwrote:
On 9/4/07, Chris.T...@jet. uk <Chris.T...@jet .ukwrote:
Thanks guys. Changing to how Python does things has a lot of geting
used to!
Do any of you have any ideas on the best way to do the following
problem:
Each loop I perform, I get a new list of Strings.
I then want to print these lists as columns adjacent to each other
starting with the first
created list in the first column and last created list in the final
column.
If you need any more information, just let me know!
Cheers

If I understand correctly what you may want is:
>l = ['1', '2', '3', '4']

you can do:
>print "\t".join(l ) # lookup join method in stringmodule,

assuming "\t" as the delimiter

or,
>for i in l:

.... print i, '\t' , # note the trailing ","

If this isnotwhat you want, post an example.

Btw, Please post new issues in a separate thread.

Cheers,
--
----
Amit Khemka
website:www.onyomo.com
wap-site:www.owap.in
I think that is very similar to what I want to do.
Say I had lists a = ["1" , "2", "3"] b = ["4", "5", "6"] c = ["7",
"8", "9"]
Stored in another list d = [a,b,c]
I want the printed output from d to be of the form:
1 4 7
2 5 8
3 6 9
>From what I am aware, there is no table module to do this. The '\t'
operator looks like it can allow this,
I am playing with it at the moment, although going for my lunch break
now!

Sep 4 '07 #19
On 9/4/07, cj***@bath.ac.u k <cj***@bath.ac. ukwrote:
On Sep 4, 11:24 am, "Amit Khemka" <khemkaa...@gma il.comwrote:
On 9/4/07, Chris.T...@jet. uk <Chris.T...@jet .ukwrote:
Thanks guys. Changing to how Python does things has a lot of geting
used to!
Do any of you have any ideas on the best way to do the following
problem:
Each loop I perform, I get a new list of Strings.
I then want to print these lists as columns adjacent to each other
starting with the first
created list in the first column and last created list in the final
column.
If you need any more information, just let me know!
Cheers
If I understand correctly what you may want is:
>>l = ['1', '2', '3', '4']
you can do:
>>print "\t".join(l ) # lookup join method in stringmodule,
assuming "\t" as the delimiter

or,
>>for i in l:
.... print i, '\t' , # note the trailing ","

If this isnotwhat you want, post an example.

Btw, Please post new issues in a separate thread.

Cheers,
--
----
Amit Khemka
website:www.onyomo.com
wap-site:www.owap.in

I think that is very similar to what I want to do.
Say I had lists a = ["1" , "2", "3"] b = ["4", "5", "6"] c = ["7",
"8", "9"]
Stored in another list d = [a,b,c]
I want the printed output from d to be of the form:
1 4 7
2 5 8
3 6 9
From what I am aware, there is no table module to do this. The '\t'
operator looks like it can allow this,
I am playing with it at the moment, although going for my lunch break
now!
Have a look at function 'zip' or function 'izip' in module "itertools" .

--
----
Amit Khemka
website: www.onyomo.com
wap-site: www.owap.in
Sep 4 '07 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
13121
by: Atul Kshirsagar | last post by:
Hello, I am using Python 2.3.2 with a C++ extention DLL in muti-threaded environment. 1. For each new thread I create a separate sub-interpreter. 2. Each thread executes multiple python statements calling the class objects in my extention DLL. 3. Before each execution I import my extention module using;
7
3981
by: ‘5ÛHH575-UAZWKVVP-7H2H48V3 | last post by:
(see end of message for example code) When an instance has a dynamically assigned instance method, deepcopy throws a TypeError with the message "TypeError: instancemethod expected at least 2 arguments, got 0". Tested with Python 2.3.4 on OpenBSD and Python 2.4 on Win98; same results. Is this a bug in deepcopy, how I dynamically assign the instance method or something else? (See example code for how I did it.) If you're curious as...
5
22752
by: Randall Parker | last post by:
Using Python 2.4.2 on Windows 2000 in SPE. Getting: TypeError: 'str' object is not callable on this line: TmpErrMsg1 = "State machine %s " (StateMachineName) In Winpdb 1.0.6 the StateMachineName is of type str in the Namespace |
1
1706
by: Gary Wessle | last post by:
dear python users I am not sure why I am getting **************************************************************** Traceback (most recent call last): File "my.py", line 3, in ? urlparse('http://www.cwi.nl:80/%7Eguido/Python.html') TypeError: 'module' object is not callable ****************************************************************
10
11534
by: Charles Russell | last post by:
Why does this work from the python prompt, but fail from a script? How does one make it work from a script? #! /usr/bin/python import glob # following line works from python prompt; why not in script? files=glob.glob('*.py') print files Traceback (most recent call last):
2
6758
by: AWasilenko | last post by:
I'm trying to test a few different approaches to displaying pages via Cherrypy and I'm not having much luck. Here is my code so far: import sys, cherrypy, html class Root: @cherrypy.expose def index(self, pageid = None): selection = html.Page() return selection.input()
18
15784
by: Charlie of Bolton | last post by:
Hi, everybody, Did work hard on this one, as I`m a newbies... I did write the entire below script... This script is suppose to ping: a primary IP (only one), (entered manually w raw-input) and than secondaries IP ( less than 10), (entered manually w raw-input)
1
17248
by: Charles Fox | last post by:
Hi gys -- I am looking at Numpy but getting this error when I try to get array sizes. I'm using Ubuntu Edgy with standard repositories and scipy. Any ideas? Am I doing something wrong or is it my install of scipy? $ python Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02) on linux2 Type "help", "copyright", "credits" or "license" for more information. array(,
0
9903
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10692
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10766
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10373
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7921
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5753
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5946
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4565
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.