Some CSV files come with NUL chars (\0x00) inside and the Python csv module doesn't know how to deal with it. So I think it's a great idea to have automatic NUL removal in the CSV plugin. An io.TextIOWrapper will do the job, like this one:
class NotNullTextWrapper(io.TextIOWrapper):
def read(self, *args, **kwargs):
data = super().read(*args, **kwargs)
return data.replace('\x00', '')
def readline(self, *args, **kwargs):
data = super().readline(*args, **kwargs)
return data.replace('\x00', '')
Sample file with this problem: http://arquivos.portaldatransparencia.gov.br/downloads.asp?a=2011&m=01&consulta=GastosDiretos
Exception raised: _csv.Error: line contains NULL byte
Some CSV files come with NUL chars (
\0x00) inside and the Pythoncsvmodule doesn't know how to deal with it. So I think it's a great idea to have automatic NUL removal in the CSV plugin. Anio.TextIOWrapperwill do the job, like this one:Sample file with this problem: http://arquivos.portaldatransparencia.gov.br/downloads.asp?a=2011&m=01&consulta=GastosDiretos
Exception raised:
_csv.Error: line contains NULL byte