如何看到.tar.gz压缩特定文件的解压没有内容的内容? [英] how to see the content of a particular file in .tar.gz archive without unzipping the contents?
本文介绍了如何看到.tar.gz压缩特定文件的解压没有内容的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为前abc.tar.gz有
ABC / FILE1.TXT结果
ABC / FILE2.TXT结果
ABC / ABC1 / file3.txt结果
ABC / ABC2 / file4.txt
我需要读/无解压文件显示file3.txt的内容。
感谢您的任何意见。
解决方案
进口tar文件
垃圾邮件= tarfile.open(abc.tar.gz)
如果ABC / ABC1 / file3.txt中spam.getnames():
与spam.extractfile(ABC / ABC1 / file3.txt)作为火腿:
打印ham.read()
请参阅 tar文件。
for ex abc.tar.gz has
abc/file1.txt
abc/file2.txt
abc/abc1/file3.txt
abc/abc2/file4.txt
i need to read/display the contents of file3.txt without extracting the file.
Thanks for any input.
解决方案
import tarfile
spam = tarfile.open( "abc.tar.gz" )
if "abc/abc1/file3.txt" in spam.getnames():
with spam.extractfile( "abc/abc1/file3.txt" ) as ham:
print ham.read()
See tarfile.
这篇关于如何看到.tar.gz压缩特定文件的解压没有内容的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文