argsparse

main
Tran Hau 2020-06-09 00:57:32 +07:00
parent 23715a88fd
commit fb4ab0a41c
3 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,28 @@
# [argparse](https://docs.python.org/3/library/argparse.html)
```python
import argparse
parser = argparse.ArgumentParser()
# Positional arguments
# python main.py unicorn
parser.add_argument("project", help="project name")
# Optional arguments
# Require following value
# python main.py unicorn -u anon
parser.add_argument("-u", "--user", help="user name")
# Not require following value
# python main.py unicorn -u anon -p
parser.add_argument("-p", "--patch", help="enable patch time", action="store_true")
args = parser.parse_args()
project = args.project
user = args.user
patch = bool(args.patch)
```

View File

@ -19,5 +19,6 @@ python -m venv venv
Now you can use venv with:
```sh
# Bash
source ./venv/bin/activate
```

View File

@ -38,6 +38,7 @@
- [testing](Development/go/testing.md)
- [Python](Development/python/README.md)
- [venv](Development/python/venv.md)
- [argparse](Development/python/argparse.md)
- [Docker](Development/docker.md)
- [Redis](Development/redis.md)
- [Prometheus](Development/prometheus.md)