[Python Wpg] String to integer conversion

Mike Pfaiffer mpfaiffer at callapple.org
Tue Mar 28 23:13:47 EST 2006


On March 28, 2006 08:38 pm, Stuart Williams wrote this amazing epistle:
> >>>>> Mike Pfaiffer writes:
> >
> > Subject: [Python Wpg] String to integer conversion
> >
> > Is there a simple way to check if the value of the string is numeric
> > first...
>
> The try/except is better, but there is an isdigit method on strings
> that's simpler than the regular expression, e.g.:
>
> '123'.isdigit() -> True
> 'abc'.isdigit() -> False
> '12a'.isdigit() -> False
> '  3'.isdigit() -> False (try/except on int() handles white space)
>
> Stuart.

 Thanks. Syd sent me something similar. Considering this is going to be used 
as a very rudimentary example for instruction (and it's the first full Python 
program I've written) I want to keep it simple. The try/exception is familiar 
to the Apple// folks although the syntax is different. This example could be 
useful for another article when I'm feeling more adventurous. ;-)

    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