Skip to content

Instantly share code, notes, and snippets.

@davidbj
Created February 19, 2014 02:31
Show Gist options
  • Select an option

  • Save davidbj/9085019 to your computer and use it in GitHub Desktop.

Select an option

Save davidbj/9085019 to your computer and use it in GitHub Desktop.
I. open a tar file
import tarfile
import glob
t = tarfile.open("foo.tar", 'w')
t.add("README")
for pyfile in glob.glob('*.py'):
t.add(pyfile)
t.close()
II.
import tarfile
t = tarfile.open("foo.tar")
for f in t:
print "%s %d" % (f.name, f.size)
III.
import tarfile
t = tarfile.open("foo.tar")
for f in t:
if os.path.basename(f.name) == "README":
data = t.extractfile(f).read()
print "**** %s ****" % f.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment