On 20.12.2011 22:04, Nick Dokos wrote:

I have a text file containing such data ;

         A                B                C
-------------------------------------------------------
-2.0100e-01    8.000e-02    8.000e-05
-2.0000e-01    0.000e+00   4.800e-04
-1.9900e-01    4.000e-02    1.600e-04

But I only need Section B, and I need to change the notation to ;

8.000e-02 = 0.08
0.000e+00 = 0.00
4.000e-02 = 0.04

Does it have to be python? If not, I'd go with something similar to

    sed 1,2d foo.data | awk '{printf("%.2f\n", $2);}'


Why sed and awk:

awk 'NR>2 {printf("%.2f\n", $2);}' data.txt

And in Python:

f = open("data.txt")
f.readline()    # skip header
f.readline()    # skip header
for line in f:
    print "%02s" % float(line.split()[1])
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to