Read file from line 2 or skip header row
--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Future Grid Looping
--
Chapters
00:00 Read File From Line 2 Or Skip Header Row
00:14 Accepted Answer Score 584
00:26 Answer 2 Score 111
00:37 Answer 3 Score 30
00:54 Answer 4 Score 22
01:04 Answer 5 Score 9
01:13 Thank you
--
Full question
https://stackoverflow.com/questions/4796...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #fileio
#avk47
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Future Grid Looping
--
Chapters
00:00 Read File From Line 2 Or Skip Header Row
00:14 Accepted Answer Score 584
00:26 Answer 2 Score 111
00:37 Answer 3 Score 30
00:54 Answer 4 Score 22
01:04 Answer 5 Score 9
01:13 Thank you
--
Full question
https://stackoverflow.com/questions/4796...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #fileio
#avk47
ACCEPTED ANSWER
Score 584
with open(fname) as f:
next(f)
for line in f:
#do something
ANSWER 2
Score 111
f = open(fname,'r')
lines = f.readlines()[1:]
f.close()
ANSWER 3
Score 22
If slicing could work on iterators...
from itertools import islice
with open(fname) as f:
for line in islice(f, 1, None):
pass
ANSWER 4
Score 9
f = open(fname).readlines()
firstLine = f.pop(0) #removes the first line
for line in f:
...