I would like to read in a dictionary from a config .txt
file into argparse
Current main.py
code:
parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
parser.add_argument('--config_1', action='store_true')
parser.add_argument('--config_2')
args = vars(parser.parse_args())
I can run my script like: python main.py @config.txt
Where config.txt
contains --config_1
Specifically, I would like to read in config_2
from config.txt
as a dictionary - something like:
--config_1
--config_2 {
'key1': [],
'key2': ['value1', 'value2']
}
This is a follow-up question to: Passing configs from `.txt` file into argparse? (Similar to youtube-dl's `--config-location`)
Edit: For clarification, I'm getting an error:
error: unrecognized arguments: --config_2 { 'key1': [], 'key2': ['value1', 'value2'] }