Skip to content Skip to sidebar Skip to footer

Csv Reader: Line Contains Null Byte

(This question is related to this one) I am reading parsing csv content, which has been previously loaded into memory: def ReadTxtIntoColumns(txt, columns): rows = [] print

Solution 1:

The csv module contains the following warning:

This version of the csv module doesn’t support Unicode input. Also, there are currently some issues regarding ASCII NUL characters. Accordingly, all input should be UTF-8 or printable ASCII to be safe; see the examples in section Examples.

The StringIO.StringIO object supports unicode, but if you are using the cStringIO module, then cStringIO.StringIO doesn't, and can lead to more problems.

If your data is ASCII only, simply encode txt first:

txt = txt.encode()

There could have been some fixes added to 2.7.3 that make the problem less visible.

Solution 2:

csv module has problems reading data from Unicode encoded files. Your code worked when I pasted it into the python interpreter and called it with a manually entered text string, so it should work if you try saving the file in ANSI/ASCII format, or converting it to ASCII when loading it into memory.

Post a Comment for "Csv Reader: Line Contains Null Byte"