New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CSV Sniffer fails to report mismatch of column counts #42898
Comments
If one line of a CSV file is missing one or more This leads to a totally misleading error when using This code shows the problem (Python 2.4.2, FC3 and import csv
str1 = "a,b,c,d\r\n1,2,foo bar,dead
beef\r\nthis,line,is,ok\r\n"
str2 = "a,b,c,d\r\n1,2,foo bar,dead beef\r\nthis,line
is,not\r\n"
s = csv.Sniffer()
d1 = s.sniff(str1)
d2 = s.sniff(str2)
for line in str1.split('\r\n'):
print line.count(',') print d1.delimiter for line in str2.split('\r\n'):
print line.count(',') print d2.delimiter |
Problem is still there as of Python 2.4.3. Trying to read in a file whose lines have a different number of fields, I get: Traceback (most recent call last):
File "../myscript.py", line 59, in ?
main()
File "../myscript.py", line 30, in main
reader = csv.reader(fin, dialect)
TypeError: bad argument type for built-in operation where "dialect" has been sniffed by feeding the first two lines to the Sniffer. What I expect is to either:
Thanks |
This appears to work better in 2.5 and 2.6 (it doesn't crash, though it |
Closing as won't fix. There are bound to be limits to how the Sniffer (Andrew, reopen if you want to tackle this.) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: