Message27509
If one line of a CSV file is missing one or more
commas, the delimiter detection code of the Sniffer
class fails, setting delimiter to an empty string.
This leads to a totally misleading error when using
has_header().
This code shows the problem (Python 2.4.2, FC3 and
Ubuntu Breezy):
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
print s.has_header(str1)
for line in str2.split('\r\n'):
print line.count(',')
print d2.delimiter
print s.has_header(str2)
|
|
Date |
User |
Action |
Args |
2007-08-23 14:37:48 | admin | link | issue1431091 messages |
2007-08-23 14:37:48 | admin | create | |
|