1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-08-08 22:36:48 +02:00

try/except dialect detection

This commit is contained in:
Kelly Brazil
2020-03-02 15:06:25 -08:00
parent ce184d4d57
commit b78c1509f6

View File

@ -3,7 +3,8 @@
Usage:
specify --csv as the first argument if the piped input is coming from a csv file.
the csv parser will attempt to automatically detect the delimter character.
the csv parser will attempt to automatically detect the delimiter character.
if the delimiter cannot be detected it will default to comma.
the first row of the file must be a header row.
Compatibility:
@ -123,7 +124,12 @@ def parse(data, raw=False, quiet=False):
cleandata = list(filter(None, cleandata))
if cleandata:
dialect = csv.Sniffer().sniff(data[:1024])
dialect = None
try:
dialect = csv.Sniffer().sniff(data[:1024])
except Exception:
pass
reader = csv.DictReader(cleandata, dialect=dialect)
for row in reader: