How to append a file to a tar file use python tarfile module?
问题 I want to append a file to the tar file. For example, the files in test.tar.gz are a.png, b.png, c.png . I have a new png file named a.png , I want to append to a.png to test.tar.gz and cover the old file a.png in test.tar.gz . My code: import tarfile a = tarfile.open('test.tar.gz', 'w:gz') a.add('a.png') a.close() then, all the files in test.tar.gz disappeard but a.png , if I change my code to this: import tarfile a = tarfile.open('test.tar.gz', 'a:')# or a:gz a.add('a.png') a.close() the