Skip to content

How to update loaded config file in Python #5793

Closed Answered by mikf
qx6ghqkz asked this question in Q&A
Discussion options

You must be logged in to vote

config.load() does pick up changes when called multiple times.

It doesn't remove deleted entries though. For example a "foo": "bar" setting picked up during the first load() will still stay in the global config dict (config._config) after deleting it from the config file and calling load() a second time. It only ever adds new values or updates existing ones.

so would clear() before load() work or can I do update()?

I'd recommend clear() before load(), but directly modifying config._config through update() and so on works as well and is probably faster. Make sure not to replace the existing config dict with a new one, though.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@qx6ghqkz
Comment options

Answer selected by mikf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
2 participants