float from numbers in text file

Stephen Hansen me+list/python at ixokai.io
Mon Jun 21 19:00:01 EDT 2010


On 6/21/10 3:54 PM, davidgp wrote:
> i basically tried this:
> lat =0.0
> for line in f:
>   lat = float(line)
> 
> but this gives an error.. does anyone know what i should to do?
> thanks,

"An error"?

Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> f = open("test.txt", "r")
>>> for line in f:
...     print float(line)
...
52.2375412
5.1802704

Always include what the actual error is that you're running into.

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 487 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20100621/3e65fff7/attachment-0001.sig>


More information about the Python-list mailing list