[Tutor] reading files
Alan Gauld
alan.gauld at btinternet.com
Wed Jan 29 15:08:30 CET 2014
On 29/01/14 02:09, Gabriele Brambilla wrote:
> how could I read float numbers if the data format is like this (using
> readline):
>
> 1.05519999999995 1.26758123387023 -0.314470329249235
> -0.293015360064208 6.15795761907822 1.92919102133526
> the numbers aren't equally spaced and they had not the same number of
> figures...
Just read the lines as strings and use str.split() to split them on
whitespace. You will wind up with a list of numeric strings that
can be converted using float()
If you need more info just ask about the specific issue you get
stuck on (reading, splitting, converting etc).
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list