> In short, anyone knows a simple trick provided by sage or python to
> read numbers from a file without redoing the parsing stuff ?
>
Luckily, both python's float type and Sage's RealDoubleField (or any
of the RealFields) are smart enough to convert from strings:
[craigci...@sharma ~/temp] $ cat reals.txt
3.14159
4
3.0e17
-5
[craigci...@sharma ~/temp] $ sage
----------------------------------------------------------------------
| Sage Version 4.0, Release Date: 2009-05-29 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------
sage: f = open('reals.txt')
sage: [ RDF(x) for x in f.readlines() ]
[3.14159, 4.0, 3e+17, -5.0]
sage: f.close()
sage: f = open('reals.txt')
sage: [ float(x) for x in f.readlines() ]
[3.1415899999999999, 4.0, 3e+17, -5.0]
sage: f.close()
Is that what you were looking to do? Or are your files of real numbers
formatted differently?
-cc
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---