map returns a list in Python 2, but an iterator in Python 3. That way, files will be closed only if you iterate over the result.
Never apply mapor similar “functional” functions to functions with side effects. Python is not a functional language and never will be. Use a loop for:
for o in files:
o.close()
source
share