Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin1!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'output': 0.05; 'subject:text': 0.05; 'lines,': 0.07; 'odd': 0.07; 'subject:file': 0.07; 'received:67.192': 0.09; 'received:67.192.241': 0.09; 'received:dfw.emailsrvr.com': 0.09; 'so?': 0.09; 'subject:How': 0.10; 'python': 0.11; '(use': 0.16; 'task.': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'select': 0.22; 'this?': 0.23; 'header:User- Agent:1': 0.23; 'received:emailsrvr.com': 0.24; 'file.': 0.24; '(or': 0.24; 'received:(smtp server)': 0.26; 'header:In-Reply- To:1': 0.27; 'idea': 0.28; 'am,': 0.29; 'lines': 0.31; 'gary': 0.31; 'go.': 0.31; 'subject:other': 0.31; 'file': 0.32; 'text': 0.33; 'open': 0.33; 'beginning': 0.33; 'subject:from': 0.34; 'could': 0.34; 'test': 0.35; 'but': 0.35; "didn't": 0.36; 'subject:?': 0.36; 'hi,': 0.36; 'received:10': 0.37; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'even': 0.60; 'read': 0.60; 'tell': 0.60; 'new': 0.61; 'charset:windows-1252': 0.65; 'received:10.10': 0.74; 'lack': 0.78; 'you:': 0.81 X-Virus-Scanned: OK X-Sender-Id: gary.herron@islandtraining.com Date: Mon, 13 Oct 2014 10:50:43 -0700 From: Gary Herron User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.2 MIME-Version: 1.0 To: python-list@python.org Subject: Re: How to select every other line from a text file? References: <3be64ca8-d2e7-493a-b4f3-ef114f581450@googlegroups.com> In-Reply-To: <3be64ca8-d2e7-493a-b4f3-ef114f581450@googlegroups.com> Content-Type: multipart/alternative; boundary="------------040201040806090200060000" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 76 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1413223031 news.xs4all.nl 2838 [2001:888:2000:d::a6]:36868 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79059 This is a multi-part message in MIME format. --------------040201040806090200060000 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit On 10/13/2014 10:38 AM, Rff 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? > > > Thanks, Read in your lines, keeping a counter as you go. "Select" those lines whose counter is even (or odd -- you didn't say which you wanted). So now some questions for you: * Do you know how to open a file and read in all the lines? * Do you know how to count as you do so? * Do you know how to test for evenness? (Use count%2 will be zero for even count values.) * Do you know how to write lines to an output file? Gary Herron --------------040201040806090200060000 Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable
On 10/13/2014 10:38 AM, Rff 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?


Thanks,

Read in your lines, keeping a counter as you go.=A0 "Select" those lines whose counter is even (or odd -- you didn't say which you wanted).

So now some questions for you:
  • Do you know how to open a file and read in all the lines?
  • Do you know how to count as you do so?
  • Do you know how to test for evenness?=A0=A0 (Use count%2 will b= e zero for even count values.)
  • Do you know how to write lines to an output file?
Gary Herron

--------------040201040806090200060000--