Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17607

Re: Text Processing

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news-transit.tcx.org.uk!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <d@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.049
X-Spam-Evidence '*H*': 0.90; '*S*': 0.00; 'sys': 0.05; 'python': 0.08; 'subject:Processing': 0.09; 'confused.': 0.16; 'options)': 0.16; 'stdout': 0.16; 'workaround': 0.16; 'cc:addr:python-list': 0.16; 'looked': 0.16; 'wrote:': 0.18; 'lines,': 0.18; 'cc:no real name:2**0': 0.20; 'header:In-Reply-To:1': 0.22; 'cc:2**0': 0.24; 'command': 0.24; 'module': 0.26; 'all,': 0.28; 'separate': 0.28; 'script': 0.28; 'print': 0.29; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'modules,': 0.30; 'version': 0.32; 'header:User-Agent:1': 0.33; 'there': 0.33; 'probably': 0.34; 'anything': 0.34; 'parse': 0.34; 'file': 0.36; '(to': 0.37; 'depend': 0.37; 'but': 0.37; 'run': 0.37; 'received:192': 0.37; 'open': 0.38; 'header': 0.39; 'skip:- 50': 0.39; 'received:192.168': 0.40; 'quick': 0.61; 'your': 0.61; 'details': 0.65; 'header:Reply-To:1': 0.71; 'size.': 0.71; 'reply-to:no real name:2**0': 0.72; 'subject:Text': 0.73; '02:17': 0.84; '10mb': 0.84; '0.00': 0.91
Date Tue, 20 Dec 2011 14:57:15 -0500
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110922 Thunderbird/3.1.15
MIME-Version 1.0
To Yigit Turgut <y.turgut@gmail.com>
Subject Re: Text Processing
References <209c2abf-dd56-4a7f-839b-fad92920d457@m7g2000vbc.googlegroups.com>
In-Reply-To <209c2abf-dd56-4a7f-839b-fad92920d457@m7g2000vbc.googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:VNwEME4kOZYYxq8iFM9tDtaSaIBDqBOBxaC5xBpZu/s hpuZ3vdB0fECCD9Q7BlFJ3NS4lnEB/6h6SY5UQA+Z8Dmj4XdrV tX5lw4qlXyvvlIH0Y/2f/zBbWBbWeNEC3YgCJFK4/NRgPcoKEs pcURPrpbsfuYnwLr9rmIBtv+UqHPeLziYvlmT6ICqDuwCgq9QI +bwdFhyTzUx6Or+B4DsnyWA+prt+dc5rE9XQGukFa13yBqBKzM VjClOyhvFne6Q6dlTU5aYs9sKlk79H1ujquiwZ9FAF5qa0Vx38 k39b9qdo0H18T4RMSTmzwf9dzgGiG64WisyFjP6+VNIvELmCwf txhICvqHaP6I5JHD3oFc=
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To d@davea.name
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3878.1324411044.27778.python-list@python.org> (permalink)
Lines 41
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1324411044 news.xs4all.nl 6919 [2001:888:2000:d::a6]:54794
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:17607

Show key headers only | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Text Processing Yigit Turgut <y.turgut@gmail.com> - 2011-12-20 11:17 -0800
  Re: Text Processing Dave Angel <d@davea.name> - 2011-12-20 14:57 -0500
  Re: Text Processing Jérôme <jerome@jolimont.fr> - 2011-12-20 21:03 +0100
  Re: Text Processing Nick Dokos <nicholas.dokos@hp.com> - 2011-12-20 16:04 -0500
  Re: Text Processing Alexander Kapps <alex.kapps@web.de> - 2011-12-21 01:01 +0100
    Re: Text Processing Yigit Turgut <y.turgut@gmail.com> - 2011-12-22 03:11 -0800

csiph-web