I try to use with statement and tarfile module…
with tarfile.open('/dir/dir/dir.tar.gz', 'w:gz') as fl:
fl.add('/dir/dir/dir/', arcname = '/')
So it shows the next:
Traceback (most recent call last): File "", line 1, in AttributeError: 'TarFile' object has no attribute '__exit__'
I try to create tar.gz file and close it using statement is, but it show an error. What is the problem?
Thanks!
You can use contextlib.closing, e.g.:
From docs:
contextlib.closingis available since Python 2.5 (or maybe even earlier…).