2024-04-25 17:38:21 发布
网友
我有一个'.tgz'文件,我正在使用读取'.tgz'文件的内容gzip.open打开. 获取特定行的文件名的最快方法是什么?你知道吗
with gzip.open('sample.tgz','r') as fin: for line in fin: error = checkForError(line) if error: # get the file name in which that particular error line was present else: pass
这个功能很有用,但它到底有多有用,谁都猜不透。 检查https://en.wikipedia.org/wiki/Tar_%28computing%29#Header以获取标头格式。你知道吗
import gzip fin = gzip.open("test.txt.tar","r") for i in fin: if "ustar" in i: fname,b = i.split("0",1) print fname else: print i fin.close()
注意:这是针对Linux上的Python2.7.6的,假设存档是用tar czvf创建的
tar czvf
这个功能很有用,但它到底有多有用,谁都猜不透。
检查https://en.wikipedia.org/wiki/Tar_%28computing%29#Header以获取标头格式。你知道吗
注意:这是针对Linux上的Python2.7.6的,假设存档是用
tar czvf
创建的相关问题 更多 >
编程相关推荐