对于个人项目,我正在尝试将paterns包升级到 Python 3。实际上我正在运行 test:db.py,但我在 csv 上的“__init__.py”文件中遇到以下错误班级:
这是save()函数的代码片段:在那里,我们将s定义为BytesIO()流,因此要求该函数将字节流式传输到自身的csv 文件。该错误来自以下行:
w.writerows([[csv_header_encode(name, type) for name, type in self.fields]])
TypeError: a bytes-like object is required, not 'str' ( below, also the code for this function)
Run Code Online (Sandbox Code Playgroud)
假设 csv_header_encode 传递字节,我检查了这一点,它确实如此,但不知何故,在其转换为列表时,它更改为“str”。如果我将s编码更改为 StringsIO 那么抱怨来自
f.write(BOM_UTF8)
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激。
def save(self, path, separator=",", encoder=lambda v: v, headers=False, password=None, **kwargs):
""" Exports the table to a unicode text file at the given path.
Rows in the file are separated …Run Code Online (Sandbox Code Playgroud)