Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #17832 > unrolled thread
| Started by | Jason Friedman <jason@powerpull.net> |
|---|---|
| First post | 2011-12-24 05:34 +0000 |
| Last post | 2011-12-24 05:34 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: merging argparse parsers Jason Friedman <jason@powerpull.net> - 2011-12-24 05:34 +0000
| From | Jason Friedman <jason@powerpull.net> |
|---|---|
| Date | 2011-12-24 05:34 +0000 |
| Subject | Re: merging argparse parsers |
| Message-ID | <mailman.4043.1324704889.27778.python-list@python.org> |
> I would like to have something like
>
> merged_parser = LoggingParser() + OtherParser()
>
> Which should create an argument parser with all the options composed.
>
I have used parent parsers.
http://docs.python.org/py3k/library/argparse.html#parents
I think in your case merged_parser would become more of a child, like this:
>>> mom_parser = argparse.ArgumentParser(add_help=False)
>>> mom_parser.add_argument('--arg1', type=int)
>>> dad_parser = argparse.ArgumentParser(add_help=False)
>>> dad_parser.add_argument('--arg2', type=int)
>>> child_parser = argparse.ArgumentParser(parents=[mom_parser, dad_parser])
Back to top | Article view | comp.lang.python
csiph-web