Challenge 1
Add the existing source file to the open TAR archive under the portable member name reports/notes.txt.
from pathlib import Path
from tempfile import TemporaryDirectory
import tarfile
with TemporaryDirectory() as folder:
root = Path(folder)
source = root / "notes.txt"
source.write_text("ready", encoding="utf-8")
archive_path = root / "notes.tar"
with tarfile.open(archive_path, "w") as archive:
with tarfile.open(archive_path) as archive:
assert archive.getnames() == ["reports/notes.txt"]
print("portable member name stored")
Press Ctrl⌘Enter to check your answer