Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteFor a regular text file, consume one line before starting the loop. Use next(f, None) to make an empty file safe:
with open("input.txt", encoding="utf-8") as f:
next(f, None)
for line in f:
process(line)
If the file is CSV, skip a parsed CSV record with csv.reader or let csv.DictReader use the first row as column names. Those cases require different code.
Skip one line in an ordinary text file
A Python file object can be iterated line by line. Calling next(f, None) advances it once, so the following loop starts with the second line. The default None means an empty file does not raise an exception.
with open("input.txt", encoding="utf-8") as f:
next(f, None) # discard the first line, if present
for line in f:
process(line)
Python documents file iteration as a memory-efficient way to read lines without loading the whole file into memory: Input and Output: Reading and Writing Files.
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
Use readline() instead
You can also read and discard the first line explicitly. At end-of-file, readline() returns an empty string, so this approach is also safe on an empty file:
with open("input.txt", encoding="utf-8") as f:
f.readline()
for line in f:
process(line)
A blank first line is not the same as an empty file: the blank line contains a newline character, while an empty string from readline() indicates end-of-file. If you use next(f) without a default, it raises StopIteration when the file has no lines.
Rank #2
Skip the first CSV record
Use Python’s csv module when the input is CSV. A record can contain embedded newlines, so one physical line of text is not necessarily one CSV record. The reader parses records and yields each as a list:
import csv
with open("input.csv", newline="", encoding="utf-8") as f:
reader = csv.reader(f)
next(reader, None) # discard the first parsed record, if present
for row in reader:
process(row)
Open the file with newline="" when passing it to csv.reader, as specified in the Python CSV documentation.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteUse the first CSV row as column names
If the first CSV record contains headers such as name and email, csv.DictReader uses that row as field names by default. It omits the header from the records it returns:
import csv
with open("input.csv", newline="", encoding="utf-8") as f:
for row in csv.DictReader(f):
process(row["name"])
Do not call next() on the file before creating this DictReader: doing so consumes the header, causing the first data record to be used as field names instead. If the CSV has no header, supply fieldnames deliberately; then the first row is treated as data.
Quick Recap
Best Value
Choose the right operation
- Plain text, discard one initial line: call
next(f, None)orf.readline()before iterating. - CSV, discard one record: call
next(reader, None)on acsv.reader. - CSV with a header: iterate over
csv.DictReader(f)without consuming a row first. - CSV without a header: define field names if using
DictReader, so its first data record is not mistaken for a header.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




