How can I process several selected text files without changing their originals?
Quick answer
Put only the files you intend to check in an explicit path list, then open each one in read mode and collect its result separately. For CSV files, Python’s csv module uses open(..., newline='') with csv.reader or csv.DictReader [S1]. Catch FileNotFoundError and record that path as missing—not as a successful check. This example keeps results in memory and does not write to the input files.
The question, the details, the next step.
A practical checklist
List only the exact CSV paths you intend to check.
Open each selected input with mode
"r"; usenewline=""for the CSV reader pattern.Keep results in a separate list or a deliberately separate output destination.
Record a missing path with a distinct status, not a zero-record success.
Review all statuses, and investigate missing or otherwise unhandled errors separately.
A few more useful answers
Does this example change the original CSV files?
No. It opens each input in read mode and only stores results in memory. The example does not write to any file.
What happens if one selected path does not exist?
That path receives a missing status through FileNotFoundError; it is not given an ok status or a row count.
Does this check prove that each CSV is valid for my task?
No. It counts records yielded by DictReader, but does not establish that required columns, values, or other task-specific rules are correct. Add checks that match your intended use.
Sources
References used for this guide.
- [S1] Python 3.14 csv module: reading a selected CSV file docs.python.org · Checked
