class Files(tuple):
def __new__(cls, *filePaths):
files = []
try:
for filePath in filePaths:
files.append(open(filePath))
files[-1].__enter__()
except:
for file in files:
file.close()
raise
else:
return super(Files, cls).__new__(cls, files)
def __enter__(self):
return self
def __exit__(self, *args):
for file in self:
file.close()
Diff to Previous Revision
--- revision 1 2017-03-13 13:19:24
+++ revision 2 2017-03-13 13:27:50
@@ -7,7 +7,6 @@
files[-1].__enter__()
except:
for file in files:
- print "closing", file
file.close()
raise
else: