我的目标是读取二进制文件并将其转换为文本。我的代码是:
def binary_to_text(self,file_name):
open_file = open(file_name,"rb")
with open("Binary2Text.txt", "a") as the_file:
for line in open_file:
the_file.write(binascii.b2a_uu(line))
我得到了这个错误:
binascii.Error: At most 45 bytes at once
有没有办法解决这个问题,或者除了binascii之外,我还可以使用其他模块吗?谢谢!
发布于 2019-03-05 08:42:02
binascii.b2a_uu
方法是用于执行uuencode的低级函数,在uuencode中,算法将文本输入编码为45字节块,这就是为什么输入有45字节块限制的原因。
除非你正在尝试自己实现uuencode,否则你应该简单地使用uu.encode
方法:
import uu
def binary_to_text(self, file_name):
with open("Binary2Text.txt", "a") as the_file:
the_file.write(uu.encode(file_name))
https://stackoverflow.com/questions/54993618
复制相似问题