python - How do I to turn my .tar.gz file into a file-like object for shutil.copyfileobj? -
my goal extract file out of .tar.gz file without extracting out sub directories precede desired file. trying module method off question . asked question of own seemed answer thought work didn't work fully. in short, shutil.copyfileobj isn't copying contents of file. my code now: import os import shutil import tarfile import gzip tarfile.open('rtlog_20150425t152948.gz', 'r:*') tar: member in tar.getmembers(): filename = os.path.basename(member.name) if not filename: continue source = tar.fileobj target = open('out', "wb") shutil.copyfileobj(source, target) upon running code file out created however, file empty. know file wanted extract does, in fact, have lots of information (approximately 450 kb). print(member.size) returns 1564197 . my attempts solve unsuccessful. print(type(tar.fileobj)) told me tar.fileobj <gzip _io.bufferedreader name='rtlog_20150425t15294...