python 压缩文件 调用7z_Python:如何从Python压缩的7z文件中读取一行?
(詳細介紹收益率部分)注意,我不知道這個庫,也不知道你用什么函數來獲取未壓縮的數據塊。但我的意思是:def 7zreadline(filename):
with open(filename, 'rb') as fh: #automatically closes filehandler when finished
archive = py7zlib.Archive7z(fh)
current_line = ''
for block in archive.getblock(): #I do not know how you get a block of uncompressed data, so I ''abstract'' the call, you get the idea...
current_line += block
while '\n' in current_line:
yield current_line[:current_line.index('\n')+1] # gives all until '\n' to the caller
current_line = current_line[current_line.index('\n')+1:] # now, initialize current_line with the rest of your block.
yield current_line #return the end of file
然后你可以這樣使用它:
^{pr2}$
如果知道庫的人可以得到正確的東西,編輯是受歡迎的。在
總結
以上是生活随笔為你收集整理的python 压缩文件 调用7z_Python:如何从Python压缩的7z文件中读取一行?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql行转列sql函数_SQL 将行
- 下一篇: python如何实现通知_ExASIC: