Build a reusable context manager that creates a temporary directory and cleans it up on exit.
Constraints
Example
>>> import os
>>> with TempDir() as t:
... print(os.path.isdir(t.path))
... with open(os.path.join(t.path, 'file.txt'), 'w') as f:
... f.write('hello')
... print(os.path.exists(os.path.join(t.path, 'file.txt')))
True
True
>>> print(os.path.exists(t.path)) # cleaned up after exit
False
Recent Submissions
No submissions yet — hit Run Tests to try!
Hints