在python中将txt文件另存为二进制
答
# read textfile into string
with open(“mytxtfile.txt”, “r”) as txtfile
mytextstring = txtfile.read()
# change text into a binary array
binarray = ' '.join(format(ch, 'b') for ch in bytearray(mytextstring))
# save the file
with open(binfileName, 'br+') as binfile:
binfile.write(binarray)
阅读本https://*.com/questions/18815820/convert-string-to-binary-在-蟒蛇 –