If I want to use the results of argparse.ArgumentParser()
, which is a Namespace
object, with a method that expects a dictionary or mapping-like obj
Straight from the horse's mouth:
If you prefer to have dict-like view of the attributes, you can use the standard Python idiom, vars():
>>> parser = argparse.ArgumentParser() >>> parser.add_argument('--foo') >>> args = parser.parse_args(['--foo', 'BAR']) >>> vars(args) {'foo': 'BAR'}
— The Python Standard Library, 16.4.4.6. The Namespace object