Skip to content

Commit 124c8bd

Browse files
PeterFeichtp12tic
authored andcommitted
Preprocess: Avoid unnecessary string creation
1 parent e370fdf commit 124c8bd

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

preprocess.py

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

257257
for err in parser.error_log:
258258
print("HTML WARN: {0}".format(err))
259-
text = etree.tostring(html, encoding=str, method="html")
260259

261-
f = open(fn, "w", encoding='utf-8')
262-
f.write(text)
263-
f.close()
260+
html.write(fn, encoding='utf-8', method='html')
264261

265262
def preprocess_css_file(fn):
266263

@@ -304,13 +301,9 @@ def main():
304301
preprocess_html_file(root, fn, rename_map)
305302

306303
# append css modifications
307-
308-
f = open("preprocess-css.css", "r", encoding='utf-8')
309-
css_app = f.read()
310-
f.close()
311-
f = open(os.path.join(root, 'common/site_modules.css'), "a", encoding='utf-8')
312-
f.write(css_app)
313-
f.close()
304+
with open(os.path.join(root, 'common/site_modules.css'), "a") as out:
305+
with open("preprocess-css.css", "r") as pp:
306+
out.writelines(pp)
314307

315308
# clean the css files
316309

0 commit comments

Comments
 (0)