473,836 Members | 2,180 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 56512
"A.T.Hofkam p" <ha*@se-162.se.wtb.tue. nlwrote:
>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
But watch out if the lists aren't all the same length: zip won't pad out
any sequences, so it may not be exactly what is wanted here:
>>x = ['1', '2', '3']
y = ['4', '5']
for row in zip(x,y):
print ', '.join(row)
1, 4
2, 5
>>>
Sep 4 '07 #21
But watch out if the lists aren't all the same length: zip won't pad out
any sequences, so it maynotbe exactly what is wanted here:
>x = ['1', '2', '3']
y = ['4', '5']
for row in zip(x,y):

print ', '.join(row)

1, 4
2, 5
Unfortunately the lists will be of different sizes
By the way I apologise for different questions within the same thread.
When I have another question, I will make a new topic
Sep 4 '07 #22
cj***@bath.ac.u k wrote:
>But watch out if the lists aren't all the same length: zip won't pad out
any sequences, so it maynotbe exactly what is wanted here:
>>x = ['1', '2', '3']
y = ['4', '5']
for row in zip(x,y):

print ', '.join(row)

1, 4
2, 5

Unfortunately the lists will be of different sizes
In that case use:

from itertools import repeat, chain, izip
def izip_longest(*a rgs, **kwds):
fillvalue = kwds.get('fillv alue')
def sentinel(counte r = ([fillvalue]*(len(args)-1)).pop):
yield counter() # yields the fillvalue, or raises IndexError
fillers = repeat(fillvalu e)
iters = [chain(it, sentinel(), fillers) for it in args]
try:
for tup in izip(*iters):
yield tup
except IndexError:
pass
x = ['1', '2', '3']
y = ['4', '5']
for row in izip_longest(x, y, fillvalue='*'):
print ', '.join(row)
which gives:

1, 4
2, 5
3, *
(izip_longest is in a future version of itertools, but for
now you have to define it yourself).

Sep 4 '07 #23
On Sep 4, 2:06 pm, Duncan Booth <duncan.bo...@i nvalid.invalidw rote:
cj...@bath.ac.u k wrote:
But watch out if the lists aren't all the same length: zip won't pad out
any sequences, so it maynotbe exactly what is wanted here:
>x = ['1', '2', '3']
y = ['4', '5']
for row in zip(x,y):
print ', '.join(row)
1, 4
2, 5
Unfortunately the lists will be of different sizes

In that case use:

from itertools import repeat, chain, izip
def izip_longest(*a rgs, **kwds):
fillvalue = kwds.get('fillv alue')
def sentinel(counte r = ([fillvalue]*(len(args)-1)).pop):
yield counter() # yields the fillvalue, or raises IndexError
fillers = repeat(fillvalu e)
iters = [chain(it, sentinel(), fillers) for it in args]
try:
for tup in izip(*iters):
yield tup
except IndexError:
pass

x = ['1', '2', '3']
y = ['4', '5']
for row in izip_longest(x, y, fillvalue='*'):
print ', '.join(row)

which gives:

1, 4
2, 5
3, *

(izip_longest is in a future version of itertools, but for
now you have to define it yourself).
Thanks guys

I have a list of lists such as
a = ["1" , "2"] b = ["4", "5", "6"] c = ["7",8", "9"]
Stored in another list: d = [a,b,c]

I know this makes me sound very stupid but how would I specify
in the parameter the inner lists without having to write them all out
such as:

for row in izip_longest(d[0], d[1], d[2], fillvalue='*'):
print ', '.join(row)

i.e. How could I do the following if I didn't know how many list of
lists I had.
Sorry this sounds stupid and easy.
Thankyou very much in advance as well, you are all very helpful
indeed.

Sep 4 '07 #24
cj***@bath.ac.u k a écrit :
(snip)
Thanks guys

I have a list of lists such as
a = ["1" , "2"] b = ["4", "5", "6"] c = ["7",8", "9"]
Stored in another list: d = [a,b,c]

I know this makes me sound very stupid but how would I specify
in the parameter the inner lists without having to write them all out
such as:

for row in izip_longest(d[0], d[1], d[2], fillvalue='*'):
print ', '.join(row)

i.e. How could I do the following if I didn't know how many list of
lists I had.
for row in izip_longest(*d , fillvalue='*'):
print ', '.join(row)
HTH
Sep 4 '07 #25
On Sep 4, 3:20 pm, Bruno Desthuilliers <bruno.
42.desthuilli.. .@wtf.websitebu ro.oops.comwrot e:
cj...@bath.ac.u k a écrit :
(snip)
Thanks guys
I have a list of lists such as
a = ["1" , "2"] b = ["4", "5", "6"] c = ["7",8", "9"]
Stored in another list: d = [a,b,c]
I know this makes me sound very stupid but how would I specify
in the parameter the inner lists without having to write them all out
such as:
for row in izip_longest(d[0], d[1], d[2], fillvalue='*'):
print ', '.join(row)
i.e. How could I do the following if I didn't know how many list of
lists I had.

for row in izip_longest(*d , fillvalue='*'):
print ', '.join(row)

HTH
I thought that but when I tried it I recieved a
"Syntax Error: Invalid Syntax"
with a ^ pointing to fillvalue :S

Sep 4 '07 #26
On Sep 4, 3:20 pm, Bruno Desthuilliers <bruno.
42.desthuilli.. .@wtf.websitebu ro.oops.comwrot e:
cj...@bath.ac.u k a écrit :
(snip)
Thanks guys
I have a list of lists such as
a = ["1" , "2"] b = ["4", "5", "6"] c = ["7",8", "9"]
Stored in another list: d = [a,b,c]
I know this makes me sound very stupid but how would I specify
in the parameter the inner lists without having to write them all out
such as:
for row in izip_longest(d[0], d[1], d[2], fillvalue='*'):
print ', '.join(row)
i.e. How could I do the following if I didn't know how many list of
lists I had.

for row in izip_longest(*d , fillvalue='*'):
print ', '.join(row)

HTH
I thought that, but when I tried it, I recieved a
"Syntax error: invalid syntax"
message with ^ pointing to the 'e' of fillvalue

Sep 4 '07 #27
cj***@bath.ac.u k writes:
>for row in izip_longest(*d , fillvalue='*'):
print ', '.join(row)

HTH

I thought that but when I tried it I recieved a
"Syntax Error: Invalid Syntax"
with a ^ pointing to fillvalue :S
Python isn't too happy about adding individual keyword arguments after
an explicit argument tuple. Try this instead:

for row in izip_longest(*d , **dict(fillvalu e='*')):
print ', '.join(row)
Sep 4 '07 #28
On 9/4/07, Hrvoje Niksic wrote:
Python isn't too happy about adding individual keyword arguments after
an explicit argument tuple. Try this instead:

for row in izip_longest(*d , **dict(fillvalu e='*')):
print ', '.join(row)
Or simply:

for row in izip_longest(fi llvalue='*', *d):
print ', '.join(row)

-Miles
Sep 4 '07 #29
cj***@bath.ac.u k a écrit :
On Sep 4, 3:20 pm, Bruno Desthuilliers <bruno.
42.desthuilli.. .@wtf.websitebu ro.oops.comwrot e:
>>cj...@bath.ac .uk a écrit :
(snip)

>>>Thanks guys
>>>I have a list of lists such as
a = ["1" , "2"] b = ["4", "5", "6"] c = ["7",8", "9"]
Stored in another list: d = [a,b,c]
>>>I know this makes me sound very stupid but how would I specify
in the parameter the inner lists without having to write them all out
such as:
>>>for row in izip_longest(d[0], d[1], d[2], fillvalue='*'):
print ', '.join(row)
>>>i.e. How could I do the following if I didn't know how many list of
lists I had.

for row in izip_longest(*d , fillvalue='*'):
print ', '.join(row)

HTH


I thought that but when I tried it I recieved a
"Syntax Error: Invalid Syntax"
with a ^ pointing to fillvalue :S
Yes, sorry - answered too fast, which is a cardinal sin. The
func(*sequence) is of course the right answer, but indeed you cannot
directly pass a keyword arg after it - you must either pass the keyword
args first:

izip_longest(fi llvalue='*', *d)

or wrap it in a dict and use the ** notation:

izip_longest(*d , **dict(fillvalu e='*'))

In this case, the second solution only makes sens if you already have
this dict for other reasons.
Sep 4 '07 #30

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

Similar topics

1
13118
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
3977
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
22750
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
11529
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
6752
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
15783
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
17245
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
9656
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10527
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...
0
10241
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...
0
9358
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7774
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
5812
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4443
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
2
4001
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3102
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.