for d in range(0,d2.size):
c2 += str(d2.item(d))
cf.write(chr(int(c2,2)))
在cf.write中获取错误(chr(int(c1,2)
TypeError:需要类似字节的对象,而不是“str”
代码在python 2.x上运行良好。
发布于 2021-05-05 14:45:24
在您的注释中,您说您使用参数wb
以字节形式打开文件,但是您试图将string
写入文件,这会导致错误。
要解决这个问题,您需要做的就是将字符串转换为字节
for d in range(0,d2.size):
c2 += str(d2.item(d))
cf.write(bytes(chr(int(c2,2)), 'utf-8'))
https://stackoverflow.com/questions/67259192
复制相似问题