def write_config(self, filename=None,
                     header="# Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib)\n",
                     save_old=True, verbose=True):
        r"""
        Writes out symbol values in the .config format. The format matches the
        C implementation, including ordering.

        Symbols appear in the same order in generated .config files as they do
        in the Kconfig files. For symbols defined in multiple locations, a
        single assignment is written out corresponding to the first location
        where the symbol is defined.

        See the 'Intro to symbol values' section in the module docstring to
        understand which symbols get written out.

        filename (default: None):
          Filename to save configuration to (a string).

          If None (the default), the filename in the the environment variable
          KCONFIG_CONFIG is used if set, and ".config" otherwise. See
          standard_config_filename().

        header (default: "# Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib)\n"):
          Text that will be inserted verbatim at the beginning of the file. You
          would usually want each line to start with '#' to make it a comment,
          and include a final terminating newline.

        save_old (default: True):
          If True and <filename> already exists, a copy of it will be saved to
          .<filename>.old in the same directory before the new configuration is
          written. The leading dot is added only if the filename doesn't
          already start with a dot.

          Errors are silently ignored if .<filename>.old cannot be written
          (e.g. due to being a directory).

        verbose (default: True):
          If True and filename is None (automatically infer configuration
          file), a message will be printed to stdout telling which file got
          written. This is meant to reduce boilerplate in tools.
        """
        if filename is None:
            filename = standard_config_filename()
        else:
            verbose = False

        if save_old:
            _save_old(filename)

        with self._open(filename, "w") as f:
            f.write(header)

            for node in self.node_iter(unique_syms=True):
                item = node.item

                if item.__class__ is Symbol:
                    f.write(item.config_string)

                elif expr_value(node.dep) and \
                     ((item is MENU and expr_value(node.visibility)) or
                       item is COMMENT):

                    f.write("\n#\n# {}\n#\n".format(node.prompt[0]))

        if verbose:
            print("Configuration written to '{}'".format(filename))
r"""
        Writes out symbol values in the .config format. The format matches the
        C implementation, including ordering.

        Symbols appear in the same order in generated .config files as they do
        in the Kconfig files. For symbols defined in multiple locations, a
        single assignment is written out corresponding to the first location
        where the symbol is defined.

        See the 'Intro to symbol values' section in the module docstring to
        understand which symbols get written out.

        filename (default: None):
          Filename to save configuration to (a string).

          If None (the default), the filename in the the environment variable
          KCONFIG_CONFIG is used if set, and ".config" otherwise. See
          standard_config_filename().

        header (default: "# Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib)\n"):
          Text that will be inserted verbatim at the beginning of the file. You
          would usually want each line to start with '#' to make it a comment,
          and include a final terminating newline.

        save_old (default: True):
          If True and <filename> already exists, a copy of it will be saved to
          .<filename>.old in the same directory before the new configuration is
          written. The leading dot is added only if the filename doesn't
          already start with a dot.

          Errors are silently ignored if .<filename>.old cannot be written
          (e.g. due to being a directory).

        verbose (default: True):
          If True and filename is None (automatically infer configuration
          file), a message will be printed to stdout telling which file got
          written. This is meant to reduce boilerplate in tools.