473,796 Members | 2,640 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 2040
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
2894
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
1523
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
2803
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
4719
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
3420
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
2393
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
1817
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
2313
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
1846
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
1409
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
9673
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
9524
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
10217
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
9047
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7546
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
6785
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();...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
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.