Convert String to Int and Arithmetic

Evan Klitzke evan at yelp.com
Tue Jun 12 11:27:36 EDT 2007


On 6/12/07, tereglow <tereglow at yahoo.com> wrote:
> Basically, I want to come out with 1000 for the above string.  Any
> help would be appreciated.
> Tom

There are any number of techniques you can use to parse out the
integer part of the string -- the most generic is to use the re module
to match regular expressions, but you may not have to use that module
if you know the exact form of the strings you are parsing. Once you
parse out the number into a string such as '1000000' you can just cast
it as an integer using some code like
    x = int('1000000')


-- 
Evan Klitzke <evan at yelp.com>



More information about the Python-list mailing list