CSV represents tabular records as text: one record per line, with fields separated by a delimiter. Commas are traditional, but tabs, colons, or other character sequences also work. section 6.18
Use Python’s csv module instead of manually splitting lines when reading or writing CSV. Open files with with, then choose the delimiter that matches the data. section 6.18 section 6.30
Convert passwd-style data
Implement passwd_to_csv(input_filename, output_filename): read colon-separated records, skip comment records without a user ID, and write username plus user ID separated by TAB characters. section 6.18
import csv
with open('/tmp/stuff.csv', 'w') as f:
o = csv.writer(f) #1
o.writerow(range(5)) #2
o.writerow(['a', 'b', 'c', 'd', 'e']) #3
A minimal writer demonstrates creating a csv.writer and emitting rows with writerow. section 6.18
Practice extensions include:
- Let users choose output fields and delimiters. section 6.21
- Write dictionaries, random-number rows, and summary calculations. section 6.21














