How to build a keyworded tuple?
I am trying to use ArgumentParser.set_defaults from argparse. I want a keyworded tuple like this: parser.set_defaults(bar=42, baz='badger')
I have the item from the output of ConfigParser.items which is: ('baz','badger')
.
How do I convert this into the keyworded tuple that set_defaults is ex开发者_如何学编程pecting?
If you have a list [(key, value), (key, value), ...]
, you can turn it into a dict with that_dict = dict(that_list)
. Then you can unpack it into set_defaults
, i.e. parser.set_default(**that_dict)
.
精彩评论