如何生成将保存为二进制文件的 txt 文件。 据说在web controller(odoo)中调用文件需要是二进制
最佳答案
# 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)
关于python - 在python中将txt文件保存为二进制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45974344/