Skip to content

Instantly share code, notes, and snippets.

@meejah
Created September 3, 2013 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meejah/6430613 to your computer and use it in GitHub Desktop.
Save meejah/6430613 to your computer and use it in GitHub Desktop.
a temporary directory like tempfile.NamedTemporaryFile
class TempDir(object):
def __enter__(self, *args):
self.dir_name = tempfile.mkdtemp()
return self
def __exit__(self, *args):
shutil.rmtree(self.dir_name)
def __str__(self):
return self.dir_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment