csv module and NULL data byte

John Pote johnpote at jptechnical.co.uk
Thu Mar 1 18:57:09 EST 2018


On 01/03/2018 01:35, Tim Chase wrote:
> While inelegant, I've "solved" this with a wrapper/generator
>
>    f = file(fname, …)
>    g = (line.replace('\0', '') for line in f)
I wondered about something like this but thought if there's a way of 
avoiding the extra step it would keep the execution speed up.
My next thought was to pass a custom encoder to the open() that 
translates NULLs to, say, 0x01. It won't make any difference to change 
one corrupt value to a different corrupt value.
>    reader = csv.reader(g, …)
>    for row in reader:
>      process(row)

Regards,
John




More information about the Python-list mailing list