argsparse
parent
23715a88fd
commit
fb4ab0a41c
|
@ -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)
|
||||
```
|
|
@ -19,5 +19,6 @@ python -m venv venv
|
|||
Now you can use venv with:
|
||||
|
||||
```sh
|
||||
# Bash
|
||||
source ./venv/bin/activate
|
||||
```
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue