在python中将txt文件另存为二进制

问题描述:

如何生成将作为二进制文件保存的txt文件。 据说它需要的是一个二进制文件调用网络控制器中的文件(odoo)在python中将txt文件另存为二进制

+0

阅读本https://*.com/questions/18815820/convert-string-to-binary-在-蟒蛇 –

# 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)