Python and shell configuration file

I have python scripts and shell scripts in the same folder that requires configuration. I currently have config.py for my python scripts, but I was wondering if you have one configuration file that can be easily read by both python scripts and shell scripts.

Can someone give an example of the configuration file format most suitable for reading both python and the shell.

+7
source share
3 answers

I think the simplest solution would be:

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

in you just need the source of this env file and in Python, it is easy to parse.

Spaces are not allowed around =

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

+6
source

This is true both in the shell and in python:

 NUMBER=42 STRING="Hello there" 

what else do you want?

+1
source

configobj lib can help with this.

 from configobj import ConfigObj cfg = ConfigObj('/home/.aws/config') access_key_id = cfg['aws_access_key_id'] secret_access_key = cfg['aws_secret_access_key'] 
+1
source

All Articles