我试图提取一个压缩文件夹,但不是直接使用.extractall(),我想将文件解压缩为流,以便我可以自己处理流.是否可以使用它tarfile?或者有什么建议吗?
Mar*_*ers 17
您可以file使用该.extractfile()方法从tar文件中获取每个文件作为python 对象.遍历tarfile.TarFile()实例以列出所有条目:
import tarfile
with tarfile.open(path) as tf:
for entry in tf: # list each entry one by one
fileobj = tf.extractfile(entry)
# fileobj is now an open file object. Use `.read()` to get the data.
# alternatively, loop over `fileobj` to read it line by line.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10853 次 |
| 最近记录: |