No project description provided
Project description
Class-Arguments
a new written style for argparse
一种新的argparser写法
样例代码
# example.py
from arguments import Argument, Option
class ComputeArg(Argument):
"""
THIS IS A DESCRIPTION ! ! ! !
a compute program
"""
x = Option("x", type=int, help="variable x")
y = Option("y", type=int, help="variable y")
opt = Option("--operator", "-opt", type=str, required=True, help="operator")
if __name__ == "__main__":
args = ComputeArg()
if args.opt == "x":
print(args.x * args.y)
elif args.opt == "+":
print(args.x + args.y)
elif args.operator == "-":
print(args.x - args.y)
elif args.operator == "/":
print(args.x / args.y)
样例输出
❯ python example.py --help
usage: example.py [-h] --operator OPERATOR x y
THIS IS A DESCRIPTION ! ! ! ! a compute program
positional arguments:
x variable x
y variable y
options:
-h, --help show this help message and exit
--operator OPERATOR, -opt OPERATOR
operator
❯ python example.py 1 2 -opt +
3
❯ python example.py 1 2 --operator /
0.5
❯ python example.py
usage: example.py [-h] --operator OPERATOR x y
example.py: error: the following arguments are required: x, y, --operator/-opt
安装
pip install class-arguments
说明
-
开发动机纯粹为了取悦自己而对 argparser 模块进行了包装
-
Option 的
__init__
参数与 argparser 模块的add_argument
的参数完全一致,不改变原有编写习惯
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
class_arguments-0.0.2.tar.gz
(3.2 kB
view hashes)
Built Distribution
Close
Hashes for class_arguments-0.0.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50984bb9cdc1b5dc85cd1f10dd24d8a5b1e74ce1aedead430419e976082f3ed9 |
|
MD5 | 8ad24b5b126b25d314fc85fa4026203b |
|
BLAKE2b-256 | 81bad3ab5d6f8e1c5ed5fdfbf98e7266d83223a69d9cf8767b826274a39db30d |