Created
August 23, 2011 05:27
-
-
Save olemb/1164413 to your computer and use it in GitHub Desktop.
tmp contexthandler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import shutil | |
import tempfile | |
from contextlib import contextmanager | |
@contextmanager | |
def tmpdir(suffix='', prefix='tmp', dir=None): | |
dirname = tempfile.mkdtemp(suffix=suffix, prefix=prefix, dir=dir) | |
yield dirname | |
shutil.rmtree(dirname) | |
with tmpdir() as d: | |
print(d) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment