Python Forum
is there an options parser that can handle + and ++
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
is there an options parser that can handle + and ++
#2
Argparse handles both i believe

https://docs.python.org/3/library/argpar...efix-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)
Output:
metulburr@ubuntu:~$ python3.6 test11.py --foo test {'foo': 'test', 'bar': None} metulburr@ubuntu:~$ python3.6 test11.py -f test {'foo': 'test', 'bar': None} metulburr@ubuntu:~$ python3.6 test11.py -b b {'foo': None, 'bar': 'b'} metulburr@ubuntu:~$ python3.6 test11.py --bar test {'foo': None, 'bar': 'test'} metulburr@ubuntu:~$ python3.6 test11.py --bar test ++foo tester {'foo': 'tester', 'bar': 'test'} metulburr@ubuntu:~$ python3.6 test11.py --bar test --foo tester {'foo': 'tester', 'bar': 'test'}
Recommended Tutorials:
Reply


Messages In This Thread
RE: is there an options parser that can handle + and ++ - by metulburr - Jul-20-2019, 07:42 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  command line options Skaperen 5 2,680 Aug-14-2020, 08:48 AM
Last Post: DeaD_EyE
  variable args + named options Skaperen 0 1,873 Aug-15-2018, 11:14 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020