How do I use config files?
Use case
When yo ustart using git repositories and put your code for everyone to see, you don’t want to include passwords, API keys and other information.
So hardcoding it in the code is no-go, then what…
Use config files.
Use the template
Python/yaml
You may find a gist here to help you.
- Create a config file in yaml format
- Copy
read_config(..)
to your project - Add a
config = read_config(config_filename)
in main - Use
config
as a normal dictionary
Advanced
-
add the config filename to
.gitignore
in the directoryThis will prevent it from being included in the git repo.
Bash
Here is a gist with an example.
- Create a config file using bash syntax.
- Copy the
CONFIG
andSource $CONFIG
lines to your project. - Reference the variable you need from the config file.
Further reading
see text above for links.