This commit is contained in:
Mike Bloy 2023-11-26 18:34:36 -06:00
parent a6043beb93
commit db640c9cbf
2 changed files with 16 additions and 1 deletions

6
ex5.5.py Normal file
View File

@ -0,0 +1,6 @@
import logging
from reader import read_csv_as_dicts
logging.basicConfig(level=logging.DEBUG)
port = read_csv_as_dicts("Data/missing.csv", types=[str, int, float])

View File

@ -1,4 +1,5 @@
import csv
import logging
from typing import Any, Callable, Iterable, Mapping, Optional, Sequence
@ -10,7 +11,15 @@ def convert_csv(
rows = csv.reader(lines)
if headers is None:
headers = next(rows)
records = list(map(lambda row: conv(row, headers), rows))
records = []
for n, row in enumerate(rows):
try:
records.append(conv(row, headers))
except ValueError as ex:
log = logging.getLogger(__name__)
log.warning(f"Row {n}: bad row: {row}")
log.debug(f"Reason: {ex}")
return records