Last active
September 11, 2018 15:34
-
-
Save NegatioN/928756e82b6bcc0a713be9b34b1fac3b to your computer and use it in GitHub Desktop.
ArgParse to namedtuple
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import namedtuple | |
| def argparse_to_namedtuple(argparse_parser): | |
| args = {x.dest: parser.get_default(x.dest) for x in argparse_parser._actions} | |
| args.pop('help', None) | |
| ParserTuple = namedtuple('ParserTuple', ' '.join([k for k,v in args.items()])) | |
| return ParserTuple(**args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO use simplenamespace instead of namedtuple to make object mutable and malleable https://stackoverflow.com/questions/5227839/why-does-python-not-support-record-type-i-e-mutable-namedtuple