<分区>
我正在尝试将我的代码升级到 python 3。 这条线有一些问题,
output_file = open(working_dir + "E"+str(s)+".txt", "w+")
output_file.write(','.join(headers) + "\n")
并得到这个错误TypeError: sequence item 0: expected str instance, bytes found
我试过的,
output_file.write(b",".join(headers) + b"\n")
TypeError: write() argument must be str, not bytes
我也尝试过在连接上使用 decode()
,也尝试过在打开时使用 r
和 w+b
。
如何在 python 3 中转换为 str
?