Fix Python 2 TypeError: write() argument 1 must be unicode, not str (see issue #2856)

This commit is contained in:
Marshall Greenblatt 2020-01-12 16:17:19 +02:00
parent e1132672ee
commit 894ac21532
1 changed files with 6 additions and 1 deletions

View File

@ -32,6 +32,11 @@ def write_file(name, data):
try:
with open(name, 'w', encoding='utf-8') as f:
# write the data
try:
# Python 2
f.write(data.decode('utf-8'))
except Exception as e:
# Python 3
f.write(data)
except IOError as e:
(errno, strerror) = e.args