mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-08-10 22:41:51 +02:00
try/except dialect detection
This commit is contained in:
@@ -3,7 +3,8 @@
|
|||||||
Usage:
|
Usage:
|
||||||
|
|
||||||
specify --csv as the first argument if the piped input is coming from a csv file.
|
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.
|
the first row of the file must be a header row.
|
||||||
|
|
||||||
Compatibility:
|
Compatibility:
|
||||||
@@ -123,7 +124,12 @@ def parse(data, raw=False, quiet=False):
|
|||||||
cleandata = list(filter(None, cleandata))
|
cleandata = list(filter(None, cleandata))
|
||||||
|
|
||||||
if 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)
|
reader = csv.DictReader(cleandata, dialect=dialect)
|
||||||
|
|
||||||
for row in reader:
|
for row in reader:
|
||||||
|
Reference in New Issue
Block a user