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


Groups > comp.lang.python > #79073

Re: How to select every other line from a text file?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsreader4.netcologne.de!news.netcologne.de!bcyclone03.am1.xlned.com!bcyclone03.am1.xlned.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <drsalists@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'cpython': 0.05; 'subject:text': 0.05; 'subject:file': 0.07; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; 'cc:name:python list': 0.16; 'range,': 0.16; 'task.': 0.16; 'url:svn': 0.16; 'xrange': 0.16; 'wrote:': 0.18; 'select': 0.22; 'cc:addr:python.org': 0.22; 'this?': 0.23; 'mon,': 0.24; 'file.': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; '13,': 0.31; '3.x': 0.31; 'subject:other': 0.31; 'probably': 0.32; 'text': 0.33; 'beginning': 0.33; 'subject:from': 0.34; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'read': 0.60; 'tell': 0.60; 'new': 0.61; 'zip': 0.64; 'lack': 0.78
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=x2TXp1qlw6CnqGOdQeQl9tVSG/Kdpeo+lxCHtvpEvEM=; b=Qayb6rK1Iu9wblbsWVpVG7cc8beaqrPy+Dn1tiEHumMPzW8SHMRzH2OAxS5DIXtu8X s3kmdArVpzYjAdiDmPRXg9wb1X1HQe/3aIBfdSsU5VD1onL/MWfGg4nNhBqPRp+cX714 gHAqsvlF84IqTH79pJIOHFTPELsU0otrrl/K/4oSlkVRReK5KkemLIJyFEsLV+db7pFP JHkBLqIWgB+aAa+IY3zbZupcnx4aAB9E1BXVQAZ6+Hcrx9izpJhJ8ZNp1UfK1XUyhaYs cDUQ/iw38Edn+X5N7pEcJtCG/XPvLKrzQ5Z57XkJtmUfwBXAlcziN1gXKyaHCMAVUr3A RfUA==
MIME-Version 1.0
X-Received by 10.152.25.194 with SMTP id e2mr1862352lag.32.1413246890027; Mon, 13 Oct 2014 17:34:50 -0700 (PDT)
In-Reply-To <3be64ca8-d2e7-493a-b4f3-ef114f581450@googlegroups.com>
References <3be64ca8-d2e7-493a-b4f3-ef114f581450@googlegroups.com>
Date Mon, 13 Oct 2014 17:34:49 -0700
Subject Re: How to select every other line from a text file?
From Dan Stromberg <drsalists@gmail.com>
To Rff <rwang@avnera.com>
Content-Type text/plain; charset=UTF-8
Cc Python List <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.14838.1413246898.18130.python-list@python.org> (permalink)
Lines 13
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1413246898 news.xs4all.nl 2858 [2001:888:2000:d::a6]:52664
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 3702
X-Received-Body-CRC 454731259
Xref csiph.com comp.lang.python:79073

Show key headers only | View raw


On Mon, Oct 13, 2014 at 10:38 AM, Rff <rwang@avnera.com> wrote:
> Hi,
> I have a text file. Now it is required to select every other line of that text to
>  generate a new text file. I have read through Python grammar, but still lack the
>  idea at the beginning of the task. Could you tell me some methods to get this?

Perhaps something like:
http://stromberg.dnsalias.org/svn/every-nth/trunk

It uses zip and itertools.cycle.

It's CPython 3.x though - if you need 2.x, you'd probably use xrange
instead of range, and izip instead of zip.

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


Thread

How to select every other line from a text file? Rff <rwang@avnera.com> - 2014-10-13 10:38 -0700
  Re: How to select every other line from a text file? Chris Angelico <rosuav@gmail.com> - 2014-10-14 04:46 +1100
    Re: How to select every other line from a text file? Grant Edwards <invalid@invalid.invalid> - 2014-10-13 19:04 +0000
  Re: How to select every other line from a text file? John Gordon <gordon@panix.com> - 2014-10-13 17:48 +0000
    Re: How to select every other line from a text file? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-13 19:02 +0100
    Re: How to select every other line from a text file? emile <emile@fenx.com> - 2014-10-13 11:11 -0700
    Re: How to select every other line from a text file? Joel Goldstick <joel.goldstick@gmail.com> - 2014-10-13 14:45 -0400
    Re: How to select every other line from a text file? Tim Chase <python.list@tim.thechases.com> - 2014-10-13 14:12 -0500
    Re: How to select every other line from a text file? emile <emile@fenx.com> - 2014-10-13 13:01 -0700
  Re: How to select every other line from a text file? Gary Herron <gary.herron@islandtraining.com> - 2014-10-13 10:50 -0700
  Re: How to select every other line from a text file? Tim Chase <python.list@tim.thechases.com> - 2014-10-13 12:55 -0500
  Re: How to select every other line from a text file? Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-13 23:54 +0000
  Re: How to select every other line from a text file? Dan Stromberg <drsalists@gmail.com> - 2014-10-13 17:34 -0700

csiph-web