Read file from line 2 or skip header row


Question

How can I skip the header row and start reading a file from line2?

1
208
1/25/2011 5:28:33 PM

Accepted Answer

with open(fname) as f:
    next(f)
    for line in f:
        #do something
395
1/25/2011 5:26:45 PM

f = open(fname,'r')
lines = f.readlines()[1:]
f.close()

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon