liveBook · Manning

Delimited file

As explained in Tiny Python Projects: Learn coding and testing with puzzles and games

Delimited text data is structured textual data whose fields are separated by a specified delimiter character or sequence.

Structures textual data as fields separated by a delimiter, such as a comma or tab. A header line commonly names the columns, while later lines represent records. section 19.0 section 19.5

A practical parsing workflow:

  • Read the header and split it on the delimiter. section 19.1.2
  • Split each data line, pair fields with headers, and create dictionaries. section 19.1.2
  • Use the csv module for delimited formats, then coerce numeric text with int() or float(). section 19.5

Workout data

Given exercise,reps followed by Burpees,20-50, parsing produces {'exercise': 'Burpees', 'reps': '20-50'}. The resulting records can drive a random workout and formatted table output. section 19.0 section 19.1.2

$ head -3 inputs/exercises.csv
exercise,reps
Burpees,20-50
Situps,40-100

Shows the compact CSV input that becomes a collection of named records. section 19.0

How Tiny Python Projects: Learn coding and testing with puzzles and games covers it

How deep it goes
Explains headers, splitting, zipping, dictionaries, library parsing, conversion, and malformed or missing data handling.
Examples
Demonstrates exercise and repetition records such as Burpees,20-50 and their dictionary representation.
What it assumes
Assumes familiarity with opening files, reading lines, splitting strings, and using dictionaries.
What you can do after
Apply it by parsing delimited records, converting numeric fields, and anticipating missing or malformed values.
How it connects
Connects delimited files with CSV, tab-delimited files, dictionaries, numeric conversion, and text table formatting.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Tiny Python Projects: Learn coding and testing with puzzles and games. The section links point to the parts of the book it draws on.