[Tutor] reading files

Gabriele Brambilla gb.gabrielebrambilla at gmail.com
Wed Jan 29 15:50:09 CET 2014


thanks to everyone, I've used David's method.

Gabriele


2014-01-29 Mark Lawrence <breamoreboy at yahoo.co.uk>

> On 29/01/2014 02:09, Gabriele Brambilla wrote:
>
>> Hi,
>> 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
>> 13.0780459630378        2.15175351758512e6
>>
>> the numbers aren't equally spaced and they had not the same number of
>> figures...
>>
>> thanks
>>
>> Gabriele
>>
>>
> Something like this, untested:-
>
> floats = []
> with open('myfile') as infile:
>     for line in infile:
>         floats.extend(float(f) for f in line.split())
>
> --
> My fellow Pythonistas, ask not what our language can do for you, ask what
> you can do for our language.
>
> Mark Lawrence
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140129/eb9a8b1e/attachment.html>


More information about the Tutor mailing list