Search code examples
pythonbashshellconfigurationdebian

A configuration file that can be read by python and shell


I have python scripts and shell scripts in the same folder which both need configuration. I currently have a config.py for my python scripts but I was wondering if it is possible to have a single configuration file which can be easily read by both python scripts and also shell scripts.

Can anyone give an example of the format of a configuration file best suited to being read by both python and shell.


Solution

  • I think the simplest solution will be :

    key1="value1"
    key2="value2"
    key3="value3"
    

    in you just have to source this env file and in Python, it's easy to parse.

    Spaces are not allowed around =

    For Python, see this post : Emulating Bash 'source' in Python