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 details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file class_arguments-0.0.2.tar.gz.
File metadata
- Download URL: class_arguments-0.0.2.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eec2962cb940c25f661c537c6f058b314c14d2f5a3201799cce43113443d8540
|
|
| MD5 |
654515a0ab15af2bbea3afac4f8b0821
|
|
| BLAKE2b-256 |
385f851b0be61602fdcf2eeb28074424715f7e3d76d050b29de3a8c9ef2bcdbc
|
File details
Details for the file class_arguments-0.0.2-py2.py3-none-any.whl.
File metadata
- Download URL: class_arguments-0.0.2-py2.py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50984bb9cdc1b5dc85cd1f10dd24d8a5b1e74ce1aedead430419e976082f3ed9
|
|
| MD5 |
8ad24b5b126b25d314fc85fa4026203b
|
|
| BLAKE2b-256 |
81bad3ab5d6f8e1c5ed5fdfbf98e7266d83223a69d9cf8767b826274a39db30d
|