Convert string to array of floats

Jonno jonnojohnson at gmail.com
Thu Jun 19 12:11:31 EDT 2008


Brilliant! Thanks.

On Thu, Jun 19, 2008 at 10:00 AM, Cédric Lucantis <omer at no-log.org> wrote:

> Le Thursday 19 June 2008 17:12:08 Jonno, vous avez écrit :
> > Hi,
> >
> > I'm very new to programming and python.
> >
> > I need to convert a string like this:
> > '               0.906366     2.276152       0.013369    80.773141
> > 0.002836  -107.335197       0.011462    86.846290    \n'
> > to an array of floats.
> >
>
> string = '0.906366     2.276152       0.013369    80.773141'
> array = [float(s) for s in string.split()]
>
> --
> Cédric Lucantis
> --
> http://mail.python.org/mailman/listinfo/python-list




-- 
"If a theory can't produce hypotheses, can't be tested, can't be disproven,
and can't make predictions, then it's not a theory and certainly not
science." by spisska on Slashdot, Monday April 21, 2008
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080619/5e78be5a/attachment-0001.html>


More information about the Python-list mailing list