From 11e039b65545c37a6d4232b38720489b6dbd98c1 Mon Sep 17 00:00:00 2001 From: danerlt <1598552894@qq.com> Date: Thu, 21 Nov 2019 21:51:17 +0800 Subject: [PATCH 1/2] fix open file encode error fix read utf-8 file in windows10 read to gbk encode. --- cpp2python.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp2python.py b/cpp2python.py index d0e13f1..27d8ccf 100755 --- a/cpp2python.py +++ b/cpp2python.py @@ -285,7 +285,7 @@ def process_file(in_filename, out_filename): """ generator - outputs processed file """ - with open(in_filename, 'r') as file: + with open(in_filename, 'r', encoding='utf-8') as file: lines = file.readlines() # probably would die on sources more than 100 000 lines :D with open(out_filename, 'w+') as file: for line in lines: From 5a5b4fd33d6b61114117ddc2d5554f4001ef0d7c Mon Sep 17 00:00:00 2001 From: danerlt <1598552894@qq.com> Date: Thu, 21 Nov 2019 23:43:08 +0800 Subject: [PATCH 2/2] fix write file encode error fix write file to gbk encode error --- cpp2python.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp2python.py b/cpp2python.py index 27d8ccf..c98e98c 100755 --- a/cpp2python.py +++ b/cpp2python.py @@ -287,7 +287,7 @@ def process_file(in_filename, out_filename): """ with open(in_filename, 'r', encoding='utf-8') as file: lines = file.readlines() # probably would die on sources more than 100 000 lines :D - with open(out_filename, 'w+') as file: + with open(out_filename, 'w+', encoding='utf-8') as file: for line in lines: file.write(process_line(line))