>>> import argparse >>> >>> def split_type(s): ... if ":" in s: ... return tuple(s.split(":", 1)) ... else: ... return s, 'zlib' ... >>> parser = argparse.ArgumentParser() >>> parser.add_argument('--send', type=split_type) ... >>> args = ['--send=a'] >>> print(parser.parse_args(args)) Namespace(send=('a', 'zlib')) >>> args = ['--send=a:none'] >>> print(parser.parse_args(args)) Namespace(send=('a', 'none'))
Created
May 3, 2014 14:13
-
-
Save aodag/b13f7aa38f0e6fe46788 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment