Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(python) do I use os.path.join on tar.gz files

I have a tar.gz file, and I want to extract a certain directory but not the whole thing, so I use TarFile.getmember('foo/bar'). what I want to know is if I really should be using TarFile.getmember(os.path.join('foo','bar')).

edit: I'm also wondering if I would use os.path.join for any other function within the tarfile module or zipfile moduple.

like image 636
QxQ Avatar asked Mar 15 '26 05:03

QxQ


1 Answers

No, the argument to getmember is the key inside the tar file, not a local file system path. Use the slashes.

like image 193
Mark Reed Avatar answered Mar 17 '26 19:03

Mark Reed