I have a .yml configuration file that controls all file I/O for my program depending on the client(s) I am running it for. The client name should be somewhere in the paths given in the YAML file, for example:
client: CLIENT_1
data:
raw-file-path: D://Users//product//data//raw//CLIENT_1//CLIENT_1_data.csv
processed-data-file-path: D://Users//product//data//processed//CLIENT_1//CLIENT_1_processed_data.csv
There are multiple clients and their data always lives in named subdirectories. My code ingests the raw data for each client and it generates processed data in the appropriate directories, as per the example above. In most cases I want to run the scripts for a single client, so I can edit the config.yml
file I showed, but I would like to be able to do it programmatically. I added a --clients
argument in the ArgumentParser: parser.add_argument('--clients', nargs='+', default=[], help='list of clients')
to allow for a list of clients to be given as input, for example python run.py --config config.yml --clients CLIENT_1 CLIENT_2
I would like to find a way to manipulate all these paths to point to the appropriate directory and even name the files leveraging something like f-strings, but I don't know how to do that. the closest question I found was this one: Leverage Python f-strings with Yaml files?, but it refers to Jinja2 templates which I am not familiar with. Is there a simpler way to do this?