473,724 Members | 2,236 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_req uest) > int(number_of_m essages):
print "\nRequest exceeds current available message count.
Adjusting to %s posts" % number_of_messa ges
message_request = number_of_messa ges
elif int(message_req uest) > 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_a vailable_messag e) +
int(message_req uest))

I also tried variations on a theme like:

last_message = int(first_avail able_message) + int(message_req uest)
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_mess age))
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 2036
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_availabl e_message+"-"+str(last_mess age))
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_mess age))
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************ *********@reade r1.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
2887
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
1519
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 trying hard to find out how to get it working with 'n' Characters, so you will be asked to enter a number at the beginning, asking you how many characters you want.
2
2799
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 know. Please help function GetWriterName str=document.location for i = len(str) to 1 step -1 if mid(str,i,1)="/" then
5
4716
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 invalid digits (~`!#$%^&*()+=?/). This is not working yet, I don't know why. In addition, I would like both fields to require from 1 to 12 digits for submition to continue. The text field also Lowers Case, can you tell me how to do the same on...
1
3403
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 place(like taskbar),it cant work,why?help me. this is the hook: // HookDll.cpp : Defines the initialization routines for the DLL. // #include "stdafx.h" #include "HookDll.h"
7
2390
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 me. This was inspired by Exercise 7 and Programming Problem 8 in Chapter 3 of our text. I have done Exercise 7 for you: Below you will find the ADT specification for a string of characters. It represents slightly more that a minimal string...
2
1812
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 called the function wordcount, and then the function did everything including printing out the results. That worked. Now I want to make the function return an array of pointers to struct palabra so the calling function can manage the data as it...
3
2309
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 I was understanding the chapter on policy classes was to attempt to apply them to my project. I understand the general concept of policies but I lack the knowledge and wisdom of how to identify them in an existing project. So I figured to get an...
5
1840
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 thought I would go a bit above and beyond the scope of the class and use strings. But I ran into a snag with my getgrades function. The compiler gives me the error: "81 ISO C++ forbids comparison between pointer and integer" here is the code for the...
1
1404
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 works fine. In order to display map in new html page I am using document.open and It seems i have someerror. Could anyone helpin fixing a bug here is my code StringBuilder str = new StringBuilder(); ...
0
8868
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8741
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
9388
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9241
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
9090
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...
1
6685
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
5996
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3209
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
3
2149
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.