By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,441 Members | 1,788 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,441 IT Pros & Developers. It's quick & easy.

help with str()

P: n/a
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

--
ROT 13 this address to mail me:

bar jbeq abg guerr; uvtu qrfreg zna, gura nqq - ng lnubb qbg pbz.
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Tuxtrax wrote:
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.
str(5) '5' str = "don't do this"
str(5) Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: 'str' object is not callable


Anton
Jul 18 '05 #2

P: n/a

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
Jul 18 '05 #3

P: n/a
In article <40*********************@reader1.nntp.hccnet.nl> ,
an***@vredegoor.doge.nl (Anton Vredegoor) wrote:

<snip>
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.
>>> str(5) '5' >>> str = "don't do this"
>>> str(5) Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: 'str' object is not callable >>>


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

--
ROT 13 this address to mail me:

bar jbeq abg guerr; uvtu qrfreg zna, gura nqq - ng lnubb qbg pbz.
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.