This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vvrsalob
Recipients
Date 2006-02-13.22:47:32
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
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)
History
Date User Action Args
2007-08-23 14:37:48adminlinkissue1431091 messages
2007-08-23 14:37:48admincreate