I am using the following code as a proof-of concept for parsing the FCC License View sample data set:
import csv
if __name__ == '__main__':
csv_file = open('fcc-license-view-data-sample.csv', 'rb')
dialect = csv.Sniffer().sniff(csv_file.read(1024))
csv_file.seek(0)
data = csv.DictReader(csv_file, dialect=dialect)
for item in data:
print item
After the module has printed all of the data, an exception is thrown:
File "C:\Python27\lib\csv.py", line 104, in next row = self.reader.next()_csv.Error: newline inside string
Why does this exception occur? How can I avoid it?
That CSV file sample seems to be cut off mid-line. The very end is
Note the unclosed quotes.
Just don’t process the last line if you want to operate on just the sample. I think this should work: