Understand the concept
Processing a file line by line can reduce the data held simultaneously in memory. It does not remove size limits, encoding, or validation needs. Scripts should return an exit code reflecting the outcome and emit useful contextual logs without exposing secrets or unnecessary full data.
Apply and decide
Before retrying an external operation after timeout, ask whether its effect may already have occurred. An idempotency key or reconciliation may be needed. Bound attempts and delays; permanent validation errors are not fixed by endless retries. When output replaces a file, prepare and validate it before publishing the result.
Guided workplace application
For a large batch, iterate csv.reader without accumulating all rows, specify encoding and newline="" when opening the file, and use the agreed dialect. split(",") does not interpret a quoted field containing commas. Size limits, validation, and accepted/rejected counts remain necessary. Logs should connect run_id, stage, and error category without copying unnecessary personal information. Exit status should meet the scheduler contract: printing ERROR does not by itself change that status. For external calls, distinguish confirmed failure from uncertain outcome. Retain operation identity, establish the idempotency contract, and use delays, attempt limits, and a deadline. If the outcome remains unknown, communicate that uncertainty instead of declaring success.
Explicit scheduler environment
A scheduled execution should have an identified interpreter, directory, and dependencies. A command invoked by name may resolve to another installation; a relative path may point to another directory. Setting env on a subprocess replaces implicit inheritance with the supplied mapping. Exercising that context avoids depending on an operator’s personal profile. Retain the reference and failure category, preserving the distinction between missing configuration and an empty functional result.
Overall budget and scheduler status
The retry budget includes attempts and their backoffs. Three five-second attempts with two two-second backoffs may take nineteen seconds; a fourteen-second contract requires bounding by the remaining deadline. Also define what reaches the scheduler: sys.exit(main) expects an appropriate status or None, and a string such as ok produces status 1 and text on stderr. Emit messages separately and return integer zero only when the success condition is satisfied.
An importer logs run_id, accepted and rejected row counts, and final status. It does not log passwords or the entire file.
Common pitfalls
Splitting CSV with split; retaining rows while claiming streaming; retrying effects without a contract.
Related topics: Data, types, and decisions · Collections without surprises
Useful automation leaves evidence and handles repetition and partial failure.
Reference: Python 3.14: CSV reading and writing · Python 3.14; DR Python 2026.3