From e429ded62dd5b9f963222764c62e96a560ca6bdf Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Thu, 28 Sep 2017 01:51:22 +0200 Subject: Get rid of _comment() Can be handled inline in a nicer way, especially with writelines(). --- kconfiglib.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/kconfiglib.py b/kconfiglib.py index 3368bc0..ca8b099 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -528,10 +528,12 @@ class Config(object): for item in self._top_block: item._add_config_strings(add_fn) - # Write header and configuration with open(filename, "w") as f: + # Write header if header is not None: - f.write(_comment(header) + "\n") + f.writelines(["#" + line + for line in (header + "\n").splitlines(True)]) + # Write configuration f.writelines(config_strings) def eval(self, s): @@ -3454,15 +3456,6 @@ def _lines(*args): between them.""" return "\n".join(args) -def _comment(s): - """Returns a new string with "#" inserted before each line in 's'.""" - if not s: - return "#" - res = "".join(["#" + line for line in s.splitlines(True)]) - if s.endswith("\n"): - return res + "#" - return res - def _stderr_msg(msg, filename, linenr): if filename is not None: sys.stderr.write("{}:{}: ".format(filename, linenr)) -- cgit v1.2.3