Created
April 29, 2018 11:25
-
-
Save maxpoletaev/0e7370447b52401c24632b7cb2a8686d to your computer and use it in GitHub Desktop.
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 tempfile | |
class TempFileManager(): | |
def __init__(self): | |
self.files = [] | |
def __enter__(self): | |
return self | |
def __exit__(self, *args): | |
self.close() | |
def create(self, suffix=''): | |
file = tempfile.NamedTemporaryFile(suffix=suffix) | |
self.files.append(file) | |
return file | |
def close(self): | |
for f in self.files: | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment