Skip to content

Commit 5a44213

Browse files
authored
Specify UTF-8 encoding for file writes (#38)
Some problem statements contain special characters and writing them to the file throws an error. This PR fixes this problem
1 parent 0d89061 commit 5a44213

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

leetcode_export/__main__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ def main():
229229
if not args.no_problem_statement and not os.path.exists(
230230
problem_statement_filename
231231
):
232-
with open(problem_statement_filename, "w+") as problem_statement_file:
232+
with open(
233+
problem_statement_filename, "w+", encoding="utf-8"
234+
) as problem_statement_file:
233235
problem_statement_file.write(
234236
problem_statement_template.substitute(
235237
**problem_statement.__dict__
@@ -243,7 +245,7 @@ def main():
243245
)
244246
if not os.path.exists(submission_filename):
245247
logging.info(f"Writing {submission.title_slug}/{submission_filename}")
246-
sub_file = open(submission_filename, "w+")
248+
sub_file = open(submission_filename, "w+", encoding="utf-8")
247249
sub_file.write(submission.code)
248250
sub_file.close()
249251
else:

0 commit comments

Comments
 (0)