如何遍历<class'tarfile.TarFile'>

问题描述

我试图找到一种方法来遍历tarfile中的多个文件。 Tarfile类具有两个对象,并且两个对象都在其中包含多个文件。我想遍历每个文件并执行一些操作,但是我不能这样做。我可以遍历类对象,但不能遍历文件

for file in filter_file_name:
        tar_file_obj = s3.get_object(Bucket='abc-logs',Key=file)
        tar_content = tar_file_obj['Body'].read()
        with tarfile.open(fileobj = io.BytesIO(tar_content)) as tar:
            print(tar)

之后,我得到的输出为:

<tarfile.TarFile object at 0x7ff9d35d8eb8>
<tarfile.TarFile object at 0x7ff9d35afc50>

现在上面的两个对象有多个文件,我想遍历每个文件并执行一些操作。下面是示例输出文件

<TarInfo './/logs/0005B95205BA/abc_logs/PERFORMANCE' at 0x7fc498a13f20> 
<TarInfo './/logs/0005B95205BA/abc_logs/PER/20200817120325.txt' at 0x7fc497fb2110>
<TarInfo './/logs/0005B95205BA/abc_logs/PER/20200817120325.txt' at 0x7fc497fb21d8>
<TarInfo './/logs/0005B95205BA/abc_logs/PER/20200817120325.txt' at 0x7fc497fb22a0>
<TarInfo './/logs/0005B95205BA/abc_logs/PER/20200817120325.txt' at 0x7fc497fb2368>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)