从python中的gzip文件读取 [英] Read from a gzip file in python
本文介绍了从python中的gzip文件读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是在python上介绍了gzip.
I've just make excises of gzip on python.
import gzip
f=gzip.open('Onlyfinnaly.log.gz','rb')
file_content=f.read()
print file_content
我在屏幕上没有任何输出.作为python的初学者,我想知道如果我想读取gzip文件中文件的内容该怎么办.谢谢.
And I get no output on the screen. As a beginner of python, I'm wondering what should I do if I want to read the content of the file in the gzip file. Thank you.
推荐答案
尝试通过gzip库通过gzip压缩一些数据,就像这样...
Try gzipping some data through the gzip libary like this...
import gzip
content = "Lots of content here"
f = gzip.open('Onlyfinnaly.log.gz', 'wb')
f.write(content)
f.close()
...然后按照发布的代码运行您的代码...
... then run your code as posted ...
import gzip
f=gzip.open('Onlyfinnaly.log.gz','rb')
file_content=f.read()
print file_content
此方法对我有用,因为某些原因,gzip库无法读取某些文件.
This method worked for me as for some reason the gzip library fails to read some files.
这篇关于从python中的gzip文件读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文