I decided to store my python app configurations in yml file. My yml file looks something like this:
config.yml
name: firstApp
base_dir: "Path(__file__).resolve(strict=True).parent.parent"
secret_key: "a passphrase for peppering"
mysql:
host: localhost
user: root
passwd: "my secret password"
I then import the yml file using pyyaml library:
config.py
import yaml
config = yaml.safe_load(open('path/to/config.yml'))
currently config.base_dir
returns Path(__file__).resolve(strict=True).parent.parent
but I want it to return the output of the python code which relies on running from pathlib import Path
first.
using eval
and exec
is frowned upon. But I do not see any other way around it. Looking for some guidance and a way to do this without any security concerns.
Thanks,