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


Groups > comp.lang.python > #17626

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 <alex.kapps@web.de>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.015
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'skip': 0.04; 'python:': 0.05; 'message-id:@web.de': 0.09; 'subject:Processing': 0.09; 'python?': 0.15; 'awk': 0.16; 'nick': 0.16; 'wrote:': 0.18; '>>>': 0.18; 'header:In-Reply-To:1': 0.22; 'from:addr:web.de': 0.23; "skip:' 10": 0.29; 'print': 0.29; 'does': 0.32; 'header:User- Agent:1': 0.33; 'to:addr:python-list': 0.34; 'something': 0.35; 'file': 0.36; 'similar': 0.36; 'but': 0.37; 'not,': 0.37; "i'd": 0.39; 'received:de': 0.39; 'header': 0.39; 'skip:- 50': 0.39; 'why': 0.39; 'to:addr:python.org': 0.40; 'subject:Text': 0.73; '0.00': 0.91
Date Wed, 21 Dec 2011 01:01:41 +0100
From Alexander Kapps <alex.kapps@web.de>
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE; rv:1.9.1.16) Gecko/20101125 Thunderbird/3.0.11
MIME-Version 1.0
To python-list@python.org
Subject Re: Text Processing
References <209c2abf-dd56-4a7f-839b-fad92920d457@m7g2000vbc.googlegroups.com> <20111220210321.77451e19@bouzin.lan> <7895.1324415085@alphaville.americas.hpqcorp.net>
In-Reply-To <7895.1324415085@alphaville.americas.hpqcorp.net>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:3RjBJp3ZTWEmD2gYvjxoNjIrIWeCpUM2KCxMDBq6Wbj ftp2QNoR+hJyv8ppZ4FbN+wtznnp7Ax4m9ypEMSHTx8sIf0+te /zH/62fI3kMbgx1RBo00pD7y7w37WClxCfdCw/JSKIWpV4ESl+ QqcF+QTpQyNZl1rNUkqaLOHhwsN8gPDkIfbW48naqDStjx5h0i zCKCmxn3oDSHGR/nZVa5w==
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
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.3887.1324425704.27778.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1324425704 news.xs4all.nl 6939 [2001:888:2000:d::a6]:55905
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:17626

Show key headers only | View raw


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])

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