【发布时间】:2017-10-12 11:57:58
【问题描述】:
我无法让它工作
import gzip
content = "Lots of content here"
f = gzip.open('file.txt.gz', 'a', 9)
f.write(content)
f.close()
我得到输出:
============== RESTART: C:/Users/Public/Documents/Trial_vr06.py ==============
Traceback (most recent call last):
File "C:/Users/Public/Documents/Trial_vr06.py", line 4, in <module>
f.write(content)
File "C:\Users\SONID\AppData\Local\Programs\Python\Python36\lib\gzip.py", line 260, in write
data = memoryview(data)
TypeError: memoryview: a bytes-like object is required, not 'str'
这是在Python Gzip - Appending to file on the fly 到Is it possible to compress program output within python to reduce output file's size? 的答案中链接的
我尝试过整数数据,但没有效果。这里有什么问题
【问题讨论】:
-
这个link 有同样的问题。