liveBook · Manning

Delimiter

As explained in Python Workout, Second Edition

A delimiter is a character or sequence of characters that separates adjacent fields or values in structured text.

A delimiter is a character or character sequence that separates adjacent fields in structured text. CSV commonly uses commas, but tabs and colons are also valid choices. section 6.18

When translating delimited files:

  • Tell csv.reader the input delimiter; otherwise comma-based parsing can silently misread colon-separated data. section 6.19
  • Tell csv.writer the output delimiter so emitted fields are separated as required. section 6.19
  • Handle comment or malformed lines before indexing fields; a one-field record may not contain the requested value. section 6.18 section 6.19

Convert colon-separated records to tab-separated output

reader = csv.reader(passwd, delimiter=':') writer = csv.writer(output, delimiter='\t') for row in reader: if len(row) >= 3: writer.writerow((row[0], row[2])) section 6.19

root:*:0:0::0:0:System Administrator:/var/root:/bin/sh
daemon:*:1:1::0:0:System Services:/var/root:/usr/bin/false
# I am a comment line
_ftp:*:98:-2::0:0:FTP Daemon:/var/empty:/usr/bin/false

Inspect passwd-style records whose fields are separated by colons and whose comment line must be excluded. section 6.18

How Python Workout, Second Edition covers it

How deep it goes
Explains delimiter selection, field extraction, output writing, and comment-line handling, but stops short of advanced CSV variations.
Examples
Uses comma-separated vegetables, colon-separated passwd records, tab-separated output, and configurable delimiter exercises.
What it assumes
Assumes basic Python file handling and indexing while teaching delimiter configuration and defensive field checks.
What you can do after
Apply it via Python's csv module to read, transform, and write files using different field separators.
How it connects
Connects delimiters with CSV, csv.reader, csv.writer, passwd files, and pandas.

Also explained in

Compare how 11 books explain delimiter →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Python Workout, Second Edition. The section links point to the parts of the book it draws on.