1
0

CSV sniffing

This commit is contained in:
Jon Michael Aanes 2024-09-27 00:03:02 +02:00
parent 5328352d4a
commit df0ee95030
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA

View File

@ -148,7 +148,9 @@ def normalize_dict(d: dict[str,typing.Any]) -> frozendict[str,typing.Any]:
def load_csv_file(csv_file: Path) -> list[frozendict]: def load_csv_file(csv_file: Path) -> list[frozendict]:
dicts: list[frozendict] = [] dicts: list[frozendict] = []
with open(csv_file) as csvfile: with open(csv_file) as csvfile:
reader = csv.DictReader(csvfile, dialect=CSV_DIALECT) dialect = csv.Sniffer().sniff(csvfile.read(1024))
csvfile.seek(0)
reader = csv.DictReader(csvfile, dialect=dialect)
for row in reader: for row in reader:
for k in list(row.keys()): for k in list(row.keys()):
orig = row[k] orig = row[k]