Convert String to Int and Arithmetic

Facundo Batista facundo at taniquetil.com.ar
Thu Jun 14 09:04:51 EDT 2007


tereglow wrote:


> cpuSpeed = 'Speed: 1000000000'
>
> What I would like to do is extract the '1000000000' from the string,
> and divide that by 1000 twice to get the speed of a processor in MHz.

>>> cpuSpeed = 'Speed: 1000000000'
>>> p = cpuSpeed.split(":")
>>> p
['Speed', ' 1000000000']
>>> p[1]
' 1000000000'
>>> v = int(p[1])
>>> v
1000000000
>>> v / 1000000
1000
>>> 

-- 
.   Facundo
.
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/





More information about the Python-list mailing list