Skip to content

Commit 76f06df

Browse files
committed
Avoid unnecessary string creation in preprocess.py
1 parent 366e51d commit 76f06df

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

preprocess.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,8 @@ def preprocess_html_file(root, fn, rename_map):
217217

218218
for err in parser.error_log:
219219
print("HTML WARN: {0}".format(err))
220-
text = etree.tostring(html, encoding=str, method="html")
221220

222-
f = open(fn, "w")
223-
f.write(text)
224-
f.close()
221+
html.write(fn, encoding='UTF-8', method='html')
225222

226223
def preprocess_css_file(fn):
227224
f = open(fn, "r")
@@ -264,12 +261,9 @@ def main():
264261

265262
# append css modifications
266263

267-
f = open("preprocess-css.css", "r")
268-
css_app = f.read()
269-
f.close()
270-
f = open(os.path.join(root, 'common/site_modules.css'), "a")
271-
f.write(css_app)
272-
f.close()
264+
with open("preprocess-css.css", "r") as pp, \
265+
open(os.path.join(root, 'common/site_modules.css'), "a") as out:
266+
out.writelines(pp)
273267

274268
# clean the css files
275269

0 commit comments

Comments
 (0)