is there an options parser that can handle + and ++ - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: General (https://python-forum.io/forum-1.html) +--- Forum: News and Discussions (https://python-forum.io/forum-31.html) +--- Thread: is there an options parser that can handle + and ++ (/thread-19935.html) |
is there an options parser that can handle + and ++ - Skaperen - Jul-20-2019 i am looking for an options parser that can handle options with - or -- or + or ++. it must support combining single letter options in the same argument (for both - and + including - and + in the same argument), -- or ++ alone to end options (for arguments alone or arguments that look like options), and option to argument tracking (for each argument, which options are closest, before or after it). i want to convert all my old commands written in C. or else i might have build my own options class. RE: is there an options parser that can handle + and ++ - metulburr - Jul-20-2019 Argparse handles both i believe https://docs.python.org/3/library/argparse.html#prefix-chars Im not sure beyond that as i never use + prefix for options. I would assume something like this -f/--foo or -b/--bar or +f/++foo or +b/++bar can all be used. f and foo are result back to foo key in dictionary. import argparse parser = argparse.ArgumentParser(prog='PROG', prefix_chars='-+') parser.add_argument('+f', '++foo') parser.add_argument('-f', '--foo') parser.add_argument('+b', '++bar') parser.add_argument('-b', '--bar') args = vars(parser.parse_args()) print(args)
|