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










