Skip to content

Instantly share code, notes, and snippets.

@maxpoletaev
Created April 29, 2018 11:25
Show Gist options
  • Save maxpoletaev/0e7370447b52401c24632b7cb2a8686d to your computer and use it in GitHub Desktop.
Save maxpoletaev/0e7370447b52401c24632b7cb2a8686d to your computer and use it in GitHub Desktop.
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