Modified version of argparse which remembers the order of CLI arguments
Project description
ordered_argparse
Version of Python's standard library's argparse
which also remembers the order of command line arguments.
Installation
Install with pip install ordered_argparse
.
Usage
Create an instance of ArgumentParser
as usual. Use namespace=ordered_argparse.OrderedNamespace()
. Access arguments in declaration order by calling parser's .ordered()
method.
import ordered_argparse
parser = ordered_argparse.ArgumentParser()
parser.add_argument("--foo", action="store_true", help="foo")
parser.add_argument("--bar", action="store_true", help="bar")
# Use OrderedNamespace when parsing CLI arguments
args = parser.parse_args(["--foo", "--bar"], namespace=ordered_argparse.OrderedNamespace())
# Access ordered arguments by calling .ordered()
for arg in args.ordered():
print(f"{arg}")
Compatibility with argcomplete
ordered_argparse only works with argcomplete
as long as you don't use subparsers. If you use subparsers, you need ordered_argcomplete
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ordered_argparse-1.0.5.tar.gz
(2.9 kB
view hashes)
Built Distribution
Close
Hashes for ordered_argparse-1.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2062dc6901f865c69e19c2f2e6b01f2496dba095d10dc0a013f0d282c50d72fe |
|
MD5 | d3aad823d38c8d1cf2f6e98ee014311e |
|
BLAKE2b-256 | fb390ce3aa49cbf602e5e4276b178217ebeb4f44bc0c9db4147cd53778f73435 |