MCPcopy
hub / github.com/dabeaz-course/python-mastery / convert_csv

Function convert_csv

Solutions/7_6/reader.py:8–20  ·  view source on GitHub ↗
(lines, converter, *, headers=None)

Source from the content-addressed store, hash-verified

6log = logging.getLogger(__name__)
7
8def convert_csv(lines, converter, *, headers=None):
9 rows = csv.reader(lines)
10 if headers is None:
11 headers = next(rows)
12
13 records = []
14 for rowno, row in enumerate(rows, start=1):
15 try:
16 records.append(converter(headers, row))
17 except ValueError as e:
18 log.warning('Row %s: Bad row: %s', rowno, row)
19 log.debug('Row %s: Reason: %s', rowno, row)
20 return records
21
22def csv_as_dicts(lines, types, *, headers=None):
23 return convert_csv(lines,

Callers 2

csv_as_dictsFunction · 0.70
csv_as_instancesFunction · 0.70

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected