我正在尝试读取文件的内容并将其转换为实际存储在内存中的内容(如果我写入)
file = open("filename","br")
binary = "0b"
for i in file.read():
binary += bin(i)[2:]
会binary等于内存中存储的实际值吗?如果是这样,我怎样才能将其转换回字符串?
编辑:我尝试过
file = open("filename.txt","br")
binary = ""
for i in file.read():
binary += bin(i)[2:]
stored = ""
for bit in binary:
stored += bit
if len(stored) == 7:
print(chr(eval("0b"+stored)), end="")
stored = ""
它工作得很好,直到它到达一个空格,然后它变成了奇怪的符号和混合的字母。
婷婷同学_
相关分类