所以任务是压缩.txt文件,我在这里做的是那个
的代码import gzip
import shutil
with open('dictionary.txt', 'rb') as f_input, gzip.open('dictionary.txt.gz', 'wb') as f_output:
shutil.copyfileobj(f_input, f_output)
现在我的任务是打开该压缩文件并重新创建全文,包括标点符号和大小写。
这是我现在所得到的,但它并不是很有效:/感觉像是非常错误。
import gzip
with gzip.open('dictionary.txt.gz', 'rb') as f:
file_content = f.read()
如果有人能够理解为什么这不起作用会非常感激。 我只需要打开一个压缩文件并重新创建全文。enter image description here
下面的图片是压缩文件和.txt文件中的内容