[Python Wpg] String to integer conversion

Mike Pfaiffer mpfaiffer at callapple.org
Tue Mar 28 17:50:59 EST 2006


 I have one last thing to do before I can clean up the program I was talking 
about at the last meeting. Fifteen minutes of work plus testing actually. 
This is a tough one. As the title suggests I want to convert a string to an 
integer. I can use the atoi or int functions. These work well if the contents 
of the string is an actual integer. If someone decides to say... put their 
name in the string (through a raw_input function) then the function crashes. 
Is there a simple way to check if the value of the string is numeric first or 
better yet return zero if the value of the string contains alphabetic 
characters?

 The routine isn't complete yet. I'm taking a break at the moment. When I get 
back I'll implement it as if the user always types in an integer. This way I 
can do some testing and clean up. After everything is up and running properly 
I'll make it available on the web.

    Later
    Mike


-- 
+----------------------------------------------------------------------+
|Call-A.P.P.L.E. and the Digital Civilization http://www.callapple.org |
|   http://members.shaw.ca/pfaiffer = Mike Pfaiffer (B.A., B.Sc.)      |
+----------------------------------------------------------------------+
----- BEGIN GEEK CODE BLOCK -----
Version: 3.12
GCS/G/IT/PA/SS d s+:- a? C++ UL L++ W++ N++ o+ K- w(---) O+@ M++@ V PS+
PE !PGP t+ 5+ X R tv b+ DI+++ D++ G e++* h! r-- !y-- UF++
------ END GEEK CODE BLOCK ------



More information about the Winnipeg mailing list