473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Why TypeError: 'str' object is not callable?

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 |
Local window of local variables. It even has the string value I expect
of 'ExampleAO'. That string variable was originally set in another
variable by reading a socket packet field. Then it was assigned to
StateMachineName.

I'm not using str as a variable. I searched all my source code.

So why can't I do this?

Is there a way to test what "str" is? Maybe importing the minidom
messed up what str is? This code used to work. I am trying to figure
out what caused it to cease to work.

Any ideas?

Mar 22 '06 #1
5 22716
Randall Parker wrote:
Using Python 2.4.2 on Windows 2000 in SPE.

Getting:
TypeError: 'str' object is not callable

on this line:

You have a boo boo
TmpErrMsg1 = "State machine %s " (StateMachineName)
Should be

TmpErrMsg1 = "State machine %s " %(StateMachineName)
In Winpdb 1.0.6 the StateMachineName is of type str in the Namespace |
Local window of local variables. It even has the string value I expect
of 'ExampleAO'. That string variable was originally set in another
variable by reading a socket packet field. Then it was assigned to
StateMachineName.

I'm not using str as a variable. I searched all my source code.

So why can't I do this?

Is there a way to test what "str" is? Maybe importing the minidom
messed up what str is? This code used to work. I am trying to figure
out what caused it to cease to work.

Any ideas?

--

Carl J. Van Arsdall
cv*********@mvista.com
Build and Release
MontaVista Software

Mar 22 '06 #2
On 22 Mar 2006 12:10:49 -0800, Randall Parker wrote:

TmpErrMsg1 = "State machine %s " (StateMachineName)


TmpErrMsg1 = "State machine %s " % (StateMachineName)

--
Richard
Mar 22 '06 #3
Carl J. Van Arsdall wrote:
Randall Parker wrote:

Getting:
TypeError: 'str' object is not callable

on this line:


You have a boo boo

TmpErrMsg1 = "State machine %s " (StateMachineName)


Should be

TmpErrMsg1 = "State machine %s " %(StateMachineName)


And the reason for the error message is, when you write
a(b)

Python interprets this as, call the object a, passing the parameter b.
If a is a string - a 'str' object - Python attempts to call the string.
Strings are not callable so you get the error message you see.

Kent
Mar 22 '06 #4
Argh!

I do not know what happened to the percent signs. They used to be
there. Sorry to waste the time of so many people.

Mar 22 '06 #5
Randall Parker wrote:
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 |
Local window of local variables. It even has the string value I expect
of 'ExampleAO'. That string variable was originally set in another
variable by reading a socket packet field. Then it was assigned to
StateMachineName.

I'm not using str as a variable. I searched all my source code.

So why can't I do this?

Is there a way to test what "str" is? Maybe importing the minidom
messed up what str is? This code used to work. I am trying to figure
out what caused it to cease to work.

Any ideas?


I know several other people have given this answer:

TmpErrMsg1 = "State machine %s " % (StateMachineName)

But it deserves comment. Note that

py> Name = 'bob'
py> (Name) == Name
True

Implying that the parentheses are not neccesary. But,

py> (Name,) == Name
False

Which may cause some confusion because

py> "%s" % Name == "%s" % (Name,)
True

Implying that a tuple is not necessary. Now,

py> Name, Name
('bob', 'bob')

So one would expect

py> (Name, Name) == (Name, Name)
True

But, by the same token, one would not expect

py> Name, Name == (Name, Name)
('bob', False)

This comes from operator precedence, where == binds tighther than does
",", and so does '%' bind tighter than ",". For example,

py> "%s" % StateMachineName == "%s" % (StateMachineName,)
True
py> "%s%s" % StateMachineName, StateMachineName
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: not enough arguments for format string

So Beware!

James
--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
Mar 22 '06 #6

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

Similar topics

1
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...
7
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...
1
by: Paul Du Bois | last post by:
Using win32 python 2.4.1, I have a minimal test program: def generate(): raise TypeError('blah') yield "" print "\n".join((generate())) Executing the program gives:
1
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 ?...
10
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...
2
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...
33
by: christophertidy | last post by:
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...
18
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) ...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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,...
0
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...

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.