473,322 Members | 1,699 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,322 software developers and data experts.

help with str()

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
3 2018
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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Helmut Jarausch | last post by:
Hi, entering help('rstrip') or help('ljust') into IDLE's shell window I only get no Python documentation found ...
7
by: mx2k | last post by:
Hello @ all, we have written a small program (code below) for our own in-developement rpg system, which is getting values for 4 RPG-Characters and doing some calculations with it. now we're...
2
by: Goran Petrovic | last post by:
I wrote a vb function, but i need it i jaavscript..i know java sintax but am not sure how to make it work. this extracts teh file name from a path...i thought strcpy..or something..but dont really...
5
by: Mike | last post by:
I'm using a script provided by e-mailanywhere, it's a little too big for me. There's 1 text field and 1 password field in a form. OnSubmit, I would like both fields to be validated to look for...
1
by: ayiiq180 | last post by:
my hook already in a dll and the handle is shared,but the hook cant work well,when i run the application,My mouse click the application's view,the hook work well,but when i click the other...
7
by: Alan Bashy | last post by:
Please, guys, In need help with this. It is due in the next week. Please, help me to implement the functions in this programm especially the first three constructor. I need them guys. Please, help...
2
by: leo2100 | last post by:
Hi, I need help with this program. The program is supposed to take a text file and identify the words in it, then it should print them and count how many times a word is repeated. At first main...
3
by: Stephen Torri | last post by:
Below is a class that is suppose to represent a segment of memory or a contents of a binary image (e.g. ELF executable). I have started to read Modern C++ Design and thought the best way to ensure...
5
by: Kelth.Raptor | last post by:
Im having some difficulty with strings here, I hope someone is kind enough to help, I do appreciate it. Im working on a grade point average calculator for my intro to programming class and I...
1
parshupooja
by: parshupooja | last post by:
Hey All, I am working in asp.net c# and Javascript. I building javascript dynamically. Actually When user click on button I want new window to open with Yahoo map. If I want map with in a page it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.