Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #79059
| 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 | <gary.herron@islandtraining.com> |
| 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 <gary.herron@islandtraining.com> |
| 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 <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.14827.1413223031.18130.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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