Text Processing

Dave Angel d at davea.name
Tue Dec 20 14:57:15 EST 2011


On 12/20/2011 02:17 PM, Yigit Turgut wrote:
> Hi all,
>
> 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
>
> Text file is approximately 10MB in size. I looked around to see if
> there is a quick and dirty workaround but there are lots of modules,
> lots of options.. I am confused.
>
> Which module is most suitable for this task ?
You probably don't need anything but sys (to parse the command options) 
and os (maybe).

open the file
     for eachline
         if one of the header lines, continue
         separate out the part you want
         print it, formatted as you like

Then just run the script with its stdout redirected, and you've got your 
new file

The details depend on what your experience with Python is, and what 
version of Python you're running.

-- 

DaveA




More information about the Python-list mailing list