Key takeaway
A quoted newline belongs to a field. A physical line count can exceed the number of data records without any duplication or missing row.
Define what the count actually counts
A delivery note reports four lines while an importer returns two business records. Before treating that as a shortfall, identify the header and whether any quoted field contains a line break. CSV separates records using syntax that can also permit line breaks inside field content. Counting newline characters ignores that distinction.
RFC 4180 describes a common CSV profile in which fields containing line breaks, commas or quotes are enclosed in double quotes, with an embedded quote represented by a doubled quote. The RFC is informational; it does not establish that every file called CSV uses exactly that profile. Preserve the producer’s actual delimiter, quoting, encoding, header and newline conventions.
Keep a complete two-record fixture
This hypothetical UTF-8 fixture has a two-field header id,note and two data records. Record A’s note contains a CRLF after first line, followed by second, with "quoted" text. Record B’s note is plain. In the CSV representation, A’s full note is quoted and its internal quote characters are doubled. The internal comma belongs to that single note field.
The source occupies four physical lines: one header line, two lines belonging to A and one line for B. A CSV reader returns three logical rows including the header, hence two data records, each with two fields. The author parsed the exact synthetic text locally using Python’s csv.reader and retained both the input and returned cells. No actual company export was examined.
| Parsed logical row | id field | note field (CRLF shown as [CRLF]) | Physical lines consumed |
|---|---|---|---|
| Header | id | note | 1 |
| Data record A | A | first line [CRLF] second, with "quoted" text | 2 |
| Data record B | B | plain | 1 |
Use parser counters for the declared purpose
Python documents csvreader.line_num as the number of source-iterator lines read, explicitly distinguishing it from records returned. Keep the returned-record counter separate from a physical-line diagnostic. If the first logical row is a header, disclose whether headline row counts include it. The same file can otherwise acquire three apparently conflicting totals: four physical lines, three returned rows and two data records.
The Python documentation also calls out newline handling when opening CSV files. Open file objects with newline='' (an empty string), as documented, choose an explicit encoding and record the dialect actually supplied to the reader. Test quoted newlines through the complete receiving path. A program that splits the file into independent newline fragments before parsing can damage a field before the CSV reader gets a chance to interpret it.
Validate field counts and malformed-record policy too. A successful reader call is not proof that a row has the intended number or meaning of columns. Empty files, a missing header, delimiter changes and an unterminated quote need defined handling. Preserve a rejected record and its diagnostic rather than silently dropping it and reporting a smaller successful import as complete.
Reconcile completeness without editing the notes
The accepted count for this fixture is two data records and two fields per record, with the original multiline note preserved. Removing its newline to force a desired physical-line total would create a derivative and change the evidence. If a receiving application requires flattened notes, document that transformation and keep its output separate from the original CSV.
A useful handoff contains the exact fixture bytes, encoding, dialect, header policy, parsed cell values, physical-line count, logical-row count, data-record count and rejected-row count. Include a comma, an escaped quote and a multiline field because each tests a different part of the syntax. Then ask the actual consumer to reproduce the expected records before accepting a larger package.
This boundary concerns record structure, rather than spreadsheet formula interpretation or correctness of the text itself. It establishes no authorization to share notes, no buyer interest and no completeness beyond the source population actually enumerated. Its practical result is a count whose unit another reviewer can reproduce.