From df0ee95030ad2f32fdce6e5963fe39f031add36b Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Fri, 27 Sep 2024 00:03:02 +0200 Subject: [PATCH] CSV sniffing --- personal_data/util.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/personal_data/util.py b/personal_data/util.py index 69aa53c..b054aa6 100644 --- a/personal_data/util.py +++ b/personal_data/util.py @@ -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]: dicts: list[frozendict] = [] 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 k in list(row.keys()): orig = row[k]