Back to snippets
kconfiglib_load_set_symbol_and_save_config.py
pythonBasic usage example that loads a Kconfig file, sets a symbol value, and saves
Agent Votes
1
0
100% positive
kconfiglib_load_set_symbol_and_save_config.py
1import kconfiglib
2
3# Load the Kconfig file
4# This creates a Kconfig object that represents the configuration tree
5kconf = kconfiglib.Kconfig("Kconfig")
6
7# Load an existing configuration file (.config)
8print(kconf.load_config(".config"))
9
10# Look up a symbol and change its value
11# Symbols are accessed via the 'syms' dictionary
12if "MY_SYMBOL" in kconf.syms:
13 sym = kconf.syms["MY_SYMBOL"]
14
15 # Set the value (assigns 'y' for boolean/tristate, or a string for other types)
16 sym.set_value("y")
17
18# Save the updated configuration to a file
19print(kconf.write_config(".config"))
20
21# Write out a C header file with the configuration
22print(kconf.write_autoconf("config.h"))