Re: Convert String to Int and Arithmetic

2007-06-14 Thread Facundo Batista
tereglow wrote: > cpuSpeed = 'Speed: 10' > > What I would like to do is extract the '10' from the string, > and divide that by 1000 twice to get the speed of a processor in MHz. >>> cpuSpeed = 'Speed: 10' >>> p = cpuSpeed.split(":") >>> p ['Speed', ' 10'] >>> p[1]

Re: Convert String to Int and Arithmetic

2007-06-13 Thread bearophileHUGS
Kay Schluehr: > >>> int(cpuSpeed.split(":")[1].strip()) Probably this suffices: int(cpuSpeed.split(":")[1]) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Convert String to Int and Arithmetic

2007-06-12 Thread James T. Dennis
tereglow <[EMAIL PROTECTED]> wrote: > Hello, > I am a complete newbie to Python and am accustomed to coding in PHP/ > Perl/Shell. I am trying to do the following: > I have a string: > cpuSpeed = 'Speed: 10' > What I would like to do is extract the '10' from the string, > and di

Re: Convert String to Int and Arithmetic

2007-06-12 Thread Evan Klitzke
On 6/12/07, tereglow <[EMAIL PROTECTED]> 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 re

Re: Convert String to Int and Arithmetic

2007-06-12 Thread tereglow
On Jun 12, 10:46 am, Kay Schluehr <[EMAIL PROTECTED]> wrote: > On 12 Jun., 16:32, tereglow <[EMAIL PROTECTED]> wrote: > > > Hello, > > > I am a complete newbie to Python and am accustomed to coding in PHP/ > > Perl/Shell. I am trying to do the following: > > > I have a string: > > > cpuSpeed = 'Sp

Re: Convert String to Int and Arithmetic

2007-06-12 Thread Kay Schluehr
On 12 Jun., 16:32, tereglow <[EMAIL PROTECTED]> wrote: > Hello, > > I am a complete newbie to Python and am accustomed to coding in PHP/ > Perl/Shell. I am trying to do the following: > > I have a string: > > cpuSpeed = 'Speed: 10' > > What I would like to do is extract the '10' fr

Re: Convert String to Int and Arithmetic

2007-06-12 Thread kyosohma
On Jun 12, 9:32 am, tereglow <[EMAIL PROTECTED]> wrote: > Hello, > > I am a complete newbie to Python and am accustomed to coding in PHP/ > Perl/Shell. I am trying to do the following: > > I have a string: > > cpuSpeed = 'Speed: 10' > > What I would like to do is extract the '10' f