Nested arguments parser
Project description
nestargs
nestargs is a Python library that defines nested program arguments. It is based on argparse.
Read this in Japanese: 日本語
Installation
pip install nestargs
Usage
Basic
Define program arguments in the same way as argparse. A nested structure can be represented by putting a dot in the program argument name.
import nestargs
parser = nestargs.NestedArgumentParser()
parser.add_argument('--apple.n', type=int)
parser.add_argument('--apple.price', type=float)
parser.add_argument('--banana.n', type=int)
parser.add_argument('--banana.price', type=float)
args = parser.parse_args('--apple.n=2 --apple.price=1.5 --banana.n=3 --banana.price=3.5'.split())
# NestedNamespace(apple=NestedNamespace(n=2, price=1.5), banana=NestedNamespace(n=3, price=3.5))
Let's take out only the program argument apple.
args.apple
# NestedNamespace(n=2, price=1.5)
You can also get each value.
args.apple.price
# 1.5
If you want a dictionary format, you can get it this way.
vars(args.apple)
# {'n': 2, 'price': 1.5}
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
nestargs-0.2.1.tar.gz
(3.1 kB
view hashes)