문제

I apologize if the questions title is not clear.

I am creating a very large compressed TarFile using python.

I need to know if when using TarFile.Add() does that close and/or finalize the file added, or can the file still be modified?

For instance, if I were to create an empty text file and then add it to a TarFile, and then modify the text file, and then close the TarFile, would the changes made to the text file appear in the TarFile, or is the text file added as it was at the time of the TarFile.Add()?

Thank you.

Note: If it makes any sort of difference, the code is running on a Ubuntu machine, and the archive is also being created on the same machine.

도움이 되었습니까?

해결책

The file contents won't get updated after you call add().

See the below code:

import tarfile

fp1 = open("hello.txt", "w")

tar = tarfile.open("myArchive.tar", "w")
tar.add("hello.txt")

fp1.write("Test String")
fp1.close()

tar.close()

After this is executed, 'hello.txt' will have "Test String", but the 'hello.txt' inside 'myArchive.tar' will be empty.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top