Subclassing file by subclassing `io.TextIOWrapper` — but what signature does its constructor have?
I think the documentation you are looking for is
class io.TextIOWrapper(buffer, encoding=None, errors=None, newline=None, line_buffering=False) A buffered text stream over a BufferedIOBase binary stream. [...]
The first argument is a binary stream, which implies something opened in binary mode by open
.
As far as "fixing" your csv file, you could also use a generator:
# untesteddef FixCsv(csv_file, *args, **kwds): "assumes text-mode file; removes NUL-bytes" if isinstance(csv_file, str): file_obj = open(csv_file, *args, **kwds) else: file_obj = csv_file for line in file_obj: yield line.replace('\x00','') file_obj.close()
But your problem is probably caused by a utf-16 encoded file.