Reputation: 164
as far as I understood, with ConfigArgParse, I can set the very main config in a config.ini file of my program and make some of those choices available via command line. However, when I set my config.ini file as default in the constructor, I get the following error:
main.py: error: unrecognized arguments: --input_base data
where --input_base is the only configuration not included in my parser as can be seen in the following:
parser = ArgParser(default_config_files=['config.ini'])
parser.add_argument('-out', '--output_base', type=str, help='xyz')
parser.add_argument('--amount', type=int, help='xyz')
parser.add_argument('--num_jobs', help='xyz')
parser.add_argument('--batch_size', type=int, help='xyz')
parser.add_argument('--queue_size', type=int, help='xyz')
parser.add_argument('--kind', choices={'long', 'short', 'both'}, help='xyz')
parser.add_argument('--level', choices={'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'}, help='xyz')
config = parser.parse_args()
Only using config.ini works fine but because of usability I have to include command line args as well.
Thanks for your help. Appreciate it!
Upvotes: 3
Views: 1913
Reputation: 81
Try change last line to:
config, unknown = parser.parse_known_args()
This will parse only known arguments (ignoring every unknown).
as in this question: Python argparse ignore unrecognised arguments
Upvotes: 4