Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As @S.Lott says, you should be opening your files in 'rb' mode, not 'rU' mode. However that may NOT be causing your current problem. As far as I know, using 'rU' mode would mess you up if there are embedded <code>\r</code> in the data, but not cause any other dramas. I also note that you have several files (all opened with 'rU' ??) but only one causing a problem.</p> <p>If the csv module says that you have a "NULL" (silly message, should be "NUL") byte in your file, then you need to check out what is in your file. I would suggest that you do this even if using 'rb' makes the problem go away.</p> <p><code>repr()</code> is (or wants to be) your debugging friend. It will show unambiguously what you've got, in a platform independant fashion (which is helpful to helpers who are unaware what <code>od</code> is or does). Do this:</p> <pre><code>print repr(open('my.csv', 'rb').read(200)) # dump 1st 200 bytes of file </code></pre> <p>and carefully copy/paste (don't retype) the result into an edit of your question (not into a comment).</p> <p>Also note that if the file is really dodgy e.g. no \r or \n within reasonable distance from the start of the file, the line number reported by <code>reader.line_num</code> will be (unhelpfully) 1. Find where the first <code>\x00</code> is (if any) by doing</p> <pre><code>data = open('my.csv', 'rb').read() print data.find('\x00') </code></pre> <p>and make sure that you dump at least that many bytes with repr or od.</p> <p>What does <code>data.count('\x00')</code> tell you? If there are many, you may want to do something like</p> <pre><code>for i, c in enumerate(data): if c == '\x00': print i, repr(data[i-30:i]) + ' *NUL* ' + repr(data[i+1:i+31]) </code></pre> <p>so that you can see the NUL bytes in context.</p> <p>If you can see <code>\x00</code> in the output (or <code>\0</code> in your <code>od -c</code> output), then you definitely have NUL byte(s) in the file, and you will need to do something like this:</p> <pre><code>fi = open('my.csv', 'rb') data = fi.read() fi.close() fo = open('mynew.csv', 'wb') fo.write(data.replace('\x00', '')) fo.close() </code></pre> <p>By the way, have you looked at the file (including the last few lines) with a text editor? Does it actually look like a reasonable CSV file like the other (no "NULL byte" exception) files?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload