2020
10-09
10-09
Python如何读写字节数据
问题你想读写二进制文件,比如图片,声音文件等等。解决方案使用模式为rb或wb的open()函数来读取或写入二进制数据。比如:#Readtheentirefileasasinglebytestringwithopen('somefile.bin','rb')asf:data=f.read()#Writebinarydatatoafilewithopen('somefile.bin','wb')asf:f.write(b'HelloWorld')在读取二进制数据时,需要指明的是所有返回的数据都是字节字符串格式的,而不是文本字符串。类...
继续阅读 >