Skip to content

Commit

Permalink
Fix EncodingWarning in file_util. Ref #232.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Mar 2, 2024
1 parent 61d103f commit 2b93ccc
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions distutils/file_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,5 @@ def write_file(filename, contents):
"""Create a file with the specified name and write 'contents' (a
sequence of strings without line terminators) to it.
"""
f = open(filename, "w")
try:
for line in contents:
f.write(line + "\n")
finally:
f.close()
with open(filename, 'w', encoding='utf-8') as f:
f.writelines(line + '\n' for line in contents)

0 comments on commit 2b93ccc

Please sign in to comment.