#bytearray数组读写问题
#bytearray数组读写问题f=open("binfile.bin","wb")
num=[5, 10, 15, 20, 25]
arr1=bytearray(num) #字符进行字节化
f.write(arr1) #写入bin文件
print(arr1)
f.close()
打印arr1,结果是
bytearray(b'\x05\n\x0f\x14\x19')
从binfile.bin读出来
fx = open('binfile.bin',"rb") # opening a file
lines5 = fx.readlines() # reading all lines 多行读取
print(lines5)
运行结果:
[b'\x05\n', b'\x0f\x14\x19']
arr1和lines5怎么不一样呢?
binfile.bin读出来的值(lines5) ,如何复原为num数组。f=open("binfile.bin","wb")num=[5, 10, 15, 20, 25]arr1=bytearray(num) #字符进行字节化f.write(arr1) #写入bin文件print(arr1)f.close() 打印arr1,结果是bytearray(b'\x05\n\x0f\x14\x19')从binfile.bin读出来fx = open('binfile.bin',"rb") # opening a file lines5 = fx.readlines() # reading all lines 多行读取print(lines5)运行结果:[b'\x05\n', b'\x0f\x14\x19']arr1和lines5怎么不一样呢?binfile.bin读出来的值(lines5) ,如何复原为num数组。