Skip to content

Instantly share code, notes, and snippets.

@NegatioN
Last active September 11, 2018 15:34
Show Gist options
  • Save NegatioN/928756e82b6bcc0a713be9b34b1fac3b to your computer and use it in GitHub Desktop.
Save NegatioN/928756e82b6bcc0a713be9b34b1fac3b to your computer and use it in GitHub Desktop.
ArgParse to namedtuple
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)
@NegatioN
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment