Skip to content

Commit caf7356

Browse files
committed
RF: refactor fix_longtable utility for codec
Specify utf8 codec for tex file processing.
1 parent baf10b6 commit caf7356

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

tools/fix_longtable.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44
import re
55
import sys
6+
import codecs
67

78
lt_LL = re.compile(
89
r"longtable}{(L+)}")
@@ -16,8 +17,9 @@ def replacer(match):
1617
raise RuntimeError("Enter path to tex file only")
1718
file_path = sys.argv[1]
1819

19-
unfixed_tex = open(file_path,'rt').readlines()
20-
write_file = open(file_path, 'wt')
21-
for line in unfixed_tex:
22-
line = lt_LL.sub(replacer, line, 1)
23-
write_file.write(line)
20+
with codecs.open(file_path, 'r', encoding='utf8') as fobj:
21+
unfixed_tex = fobj.readlines()
22+
with codecs.open(file_path, 'w', encoding='utf8') as fobj:
23+
for line in unfixed_tex:
24+
line = lt_LL.sub(replacer, line, 1)
25+
fobj.write(line)

0 commit comments

Comments
 (0)