-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeispiel_argparse.py
More file actions
31 lines (28 loc) · 916 Bytes
/
Beispiel_argparse.py
File metadata and controls
31 lines (28 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/local/bin/python3
##############################################
#
# Name: Beispiel_argparse.py
#
# Author: Peter Christen
#
# Version: 1.0
#
# Date: 10.11.2017
#
# Purpose: Beispiele mit argparse
#
##############################################
import argparse
###Parameter definieren
parser = argparse.ArgumentParser(description="Zweck des Scripts")
parser.add_argument('-v','--verbose', action='store_true', help="Beschreibung")
parser.add_argument('-f', choices=['blau', 'rot'], help="Auswahl")
group = parser.add_mutually_exclusive_group(required=False)
group.add_argument('-k', metavar='Keyword', nargs=1, help="Braucht genau eine Angabe")
group.add_argument('-n', metavar='Nummern', nargs='+', help="Mehrere Nummern", type=int)
args = parser.parse_args()
###Parameter auswerten
if args.verbose: print("v")
if args.f: print ("f",args.f)
if args.k: print ("k",args.k)
if args.n: print ("n",args.n)