We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 61d103f commit 2b93cccCopy full SHA for 2b93ccc
distutils/file_util.py
@@ -230,9 +230,5 @@ def write_file(filename, contents):
230
"""Create a file with the specified name and write 'contents' (a
231
sequence of strings without line terminators) to it.
232
"""
233
- f = open(filename, "w")
234
- try:
235
- for line in contents:
236
- f.write(line + "\n")
237
- finally:
238
- f.close()
+ with open(filename, 'w', encoding='utf-8') as f:
+ f.writelines(line + '\n' for line in contents)
0 commit comments