Python tarfile progress output?

前端 未结 6 991
旧巷少年郎
旧巷少年郎 2021-02-07 10:41

I\'m using the following code to extract a tar file:

import tarfile
tar = tarfile.open(\"sample.tar.gz\")
tar.extractall()
tar.close()

However,

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-07 10:48

    To see which file is currently being extracted, the following worked for me:

    import tarfile
    
    print "Extracting the contents of sample.tar.gz:"
    tar = tarfile.open("sample.tar.gz")
    
    for member_info in tar.getmembers():
        print "- extracting: " + member_info.name
        tar.extract(member_info)
    
    tar.close()
    

提交回复
热议问题