Skip to content

Instantly share code, notes, and snippets.

@ramn
Created November 11, 2013 14:30
Show Gist options
  • Save ramn/7413983 to your computer and use it in GitHub Desktop.
Save ramn/7413983 to your computer and use it in GitHub Desktop.
Selfdestructing tempdir (Python)
class selfdestructing_tempdir(object):
def __enter__(self):
import tempfile
self._tempdir = tempfile.mkdtemp()
return self._tempdir
def __exit__(self, type, value, traceback):
import shutil
shutil.rmtree(self._tempdir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment