ex5.5
This commit is contained in:
parent
a6043beb93
commit
db640c9cbf
6
ex5.5.py
Normal file
6
ex5.5.py
Normal 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])
|
||||||
11
reader.py
11
reader.py
@ -1,4 +1,5 @@
|
|||||||
import csv
|
import csv
|
||||||
|
import logging
|
||||||
from typing import Any, Callable, Iterable, Mapping, Optional, Sequence
|
from typing import Any, Callable, Iterable, Mapping, Optional, Sequence
|
||||||
|
|
||||||
|
|
||||||
@ -10,7 +11,15 @@ def convert_csv(
|
|||||||
rows = csv.reader(lines)
|
rows = csv.reader(lines)
|
||||||
if headers is None:
|
if headers is None:
|
||||||
headers = next(rows)
|
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
|
return records
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user