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
说明
-
开发动机纯粹为了取悦自己而对 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.1.tar.gz
(3.1 kB
view hashes)
Built Distribution
Close
Hashes for class_arguments-0.0.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31e863cd1f052bea60ff86d1bd0836a336468d93cf4f4eade605aacf0e184d22 |
|
MD5 | bbe471b6c362cd65f00b4ae32b5493fd |
|
BLAKE2b-256 | 81d5db58400969a1142bc18e89875b3c389055da351a63247ed1f20986672b26 |