Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104269
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
| Newsgroups | comp.lang.python |
| Subject | Re: Pythonic love |
| Date | Mon, 7 Mar 2016 23:19:08 +0000 |
| Lines | 39 |
| Message-ID | <mailman.2.1457392797.15725.python-list@python.org> (permalink) |
| References | <nbl0lo$5o5$1@gioia.aioe.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de n+iM+UTy+J/lK469Ue8zEAv3NeVDMdpg/TsJgshSuXaA== |
| Return-Path | <python-python-list@m.gmane.org> |
| 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; 'from:addr:yahoo.co.uk': 0.05; 'lines.': 0.07; 'csv': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.10; 'things.': 0.15; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'skip': 0.18; 'language': 0.19; 'lawrence': 0.22; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'wonder': 0.27; 'perl': 0.29; "i'd": 0.31; 'language.': 0.32; 'url:python': 0.33; 'files,': 0.35; 'something': 0.35; 'but': 0.36; 'url:org': 0.36; 'possible.': 0.36; 'url:library': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'thanks': 0.37; 'received:org': 0.37; 'things': 0.38; 'to:addr:python.org': 0.40; 'mark': 0.40; 'url:3': 0.60; 'here.': 0.62; 'charset:windows-1252': 0.62; 'skip:n 10': 0.62; 'more': 0.63; 'our': 0.64; 'pythonistas,': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | 80.234.129.0 |
| User-Agent | Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 |
| In-Reply-To | <nbl0lo$5o5$1@gioia.aioe.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21 |
| 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> |
| Xref | csiph.com comp.lang.python:104269 |
Show key headers only | View raw
On 07/03/2016 22:51, Fillmore wrote:
>
> learning Python from Perl here. Want to do things as Pythonicly as
> possible.
>
> I am reading a TSV, but need to skip the first 5 lines. The following
> works, but wonder if there's a more pythonc way to do things. Thanks
>
> ctr = 0
> with open(prfile,mode="rt",encoding='utf-8') as pfile:
> for line in pfile:
> ctr += 1
>
> if ctr < 5:
> continue
>
> allVals = line.strip().split("\t")
> print(allVals)
Something like this, completely untested.
with open(prfile,mode="rt",encoding='utf-8') as pfile:
lineIter = iter(pfile)
for _ in range(5):
next(lineIter)
for line in lineIter:
allVals = line.strip().split("\t")
print(allVals)
I'd also recommend that you use the csv module
https://docs.python.org/3/library/csv.html which can also cope with tsv
files, it's far more reliable than relying on a simple call to split().
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Pythonic love Fillmore <fillmore_remove@hotmail.com> - 2016-03-07 17:51 -0500
Re: Pythonic love Rob Gaddi <rgaddi@highlandtechnology.invalid> - 2016-03-07 22:52 +0000
Re: Pythonic love sohcahtoa82@gmail.com - 2016-03-07 15:03 -0800
Re: Pythonic love Fillmore <fillmore_remove@hotmail.com> - 2016-03-07 18:12 -0500
Re: Pythonic love Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-07 16:13 -0700
Re: Pythonic love Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-07 23:19 +0000
Re: Pythonic love jmp <jeanmichel@sequans.com> - 2016-03-08 14:25 +0100
Re: Pythonic love justin walters <walters.justin01@gmail.com> - 2016-03-08 08:49 -0800
Re: Pythonic love Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-08 16:55 +0000
Re: Pythonic love jmp <jeanmichel@sequans.com> - 2016-03-08 18:00 +0100
Re: Pythonic love justin walters <walters.justin01@gmail.com> - 2016-03-08 09:17 -0800
Re: Pythonic love jstitch@invernalia.homelinux.net (Javier Novoa C.) - 2016-03-08 11:27 -0600
Re: Pythonic love Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-03-08 21:10 -0500
csiph-web