Questions tagged «bytesio»

2
写入然后读取内存字节(BytesIO)会得到空白结果
我想尝试python BytesIO类。 作为一个实验,我尝试写入内存中的zip文件,然后从该zip文件中读取字节。因此gzip,我没有传递文件对象给,而是传递了BytesIO对象。这是整个脚本: from io import BytesIO import gzip # write bytes to zip file in memory myio = BytesIO() g = gzip.GzipFile(fileobj=myio, mode='wb') g.write(b"does it work") g.close() # read bytes from zip file in memory g = gzip.GzipFile(fileobj=myio, mode='rb') result = g.read() g.close() print(result) 但是它返回的空bytes对象result。在Python 2.7和3.4中都会发生这种情况。我想念什么?
74 python  byte  gzip  bytesio 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.