我收到了

TypeError: a bytes-like object is required, not str

但是我的str-object是字节并且已经搜索了答案 .


这是解码发生而没有错误:

for line in tmpFile:
    sl = codecs.decode(bytes(line, encoding = 'utf-8'), encoding  = 'utf-8').strip().split('\t')
    writer.writerow(sl)

如果我取出(bytes(line,encofing = 'utf-8')部分,那么我得到TypeError .
这就是我打开文件的方式:

with open(output_path, mode = 'w') as out_file:
        write_final_output(out_file, delimiter, tmpFile)

我试过用mode ='w'和编解码器打开它,我仍然遇到同样的问题,那就是我的csv文件以这样的开头读出来编码:

b'101361\x01