help with str()

R

Robert M. Emmons

No dice. In every case, I get the following error:

Traceback (most recent call last):
File "headhunter.py", line 317, in ?
response, poster = n.xhdr("from",
first_available_message+"-"+str(last_message))
TypeError: 'str' object is not callable

I have tried everything I could think of and there is only one
possibility still left that I can think of. My theory is this: by using
the int() function, I am typing the numbers in the last_message
assignment to type integer, and str() is expecting type float, or
something.

str() will work on ints. str() will even work on classes if you have
the right special method handler defined.

You might want to verify that displaying the value of "str" gives you
something like <built-in fucntion str>. You can do this by using "print
str". Might be fun to try also "print str(str)" and print "repr(str)".
You should get the same thing for these others.

Why I say that is that it is possible to assign something in your code
to str then it's no-longer associated with the built-in function you
want, then it might not be callable. You could have done this in your
function, or in the global scope for example.

Rob

Rob
 
T

Tuxtrax

Hi all.

I have need of assistance on something that should be very simple, and
is driving me absolutely batty. This is a code snippet from a short
program that downloads news headers via nntplib. getinput() is simply a
function I have defined for using raw_input in a friendly fashion.


message_request = getinput("\nHow many posts should I be interested in?
[max 10,000]")

if int(message_request) > int(number_of_messages):
print "\nRequest exceeds current available message count.
Adjusting to %s posts" % number_of_messages
message_request = number_of_messages
elif int(message_request) > 10000:
print "\nRequest exceeds program capacity. Assuming max of 10,000
posts, and continuing ...."
message_request = "10000"


The trouble comes in when I try to convert last_message into a string:

last_message = str(int(first_available_message) +
int(message_request))

I also tried variations on a theme like:

last_message = int(first_available_message) + int(message_request)
string_result = str(last message)

No dice. In every case, I get the following error:

Traceback (most recent call last):
File "headhunter.py", line 317, in ?
response, poster = n.xhdr("from",
first_available_message+"-"+str(last_message))
TypeError: 'str' object is not callable

I have tried everything I could think of and there is only one
possibility still left that I can think of. My theory is this: by using
the int() function, I am typing the numbers in the last_message
assignment to type integer, and str() is expecting type float, or
something.

I am stuck. Thanks for any help you all can provide. I appreciate it.

best regards,

Mathew
 
A

Anton Vredegoor

Tuxtrax said:
No dice. In every case, I get the following error:

Traceback (most recent call last):
File "headhunter.py", line 317, in ?
response, poster = n.xhdr("from",
first_available_message+"-"+str(last_message))
TypeError: 'str' object is not callable

Maybe this rings a bell:

Python 2.3.2 (#1, Oct 9 2003, 12:03:29)
[GCC 3.3.1 (cygming special)] on cygwin
Type "help", "copyright", "credits" or "license" for more
information. Traceback (most recent call last):

Anton
 
T

Tuxtrax

Maybe this rings a bell:

Python 2.3.2 (#1, Oct 9 2003, 12:03:29)
[GCC 3.3.1 (cygming special)] on cygwin
Type "help", "copyright", "credits" or "license" for more
information.Traceback (most recent call last):

Anton

Thanks Anton. That was exactly it. I had a variable ealier in the
program called str. Changed that variable name to another, and the str()
function worked fine. DOH!

I knew it was something simple. Most of my fopahs are.

again, thanks,

Mathew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,121
Latest member
LowellMcGu
Top