forked from ovh/pci-test
Ex.1
This commit is contained in:
parent
9ef89a992f
commit
6e7fe656b4
4
ex1/a.py
Normal file
4
ex1/a.py
Normal file
@ -0,0 +1,4 @@
|
||||
import sys
|
||||
|
||||
frase = " ".join(sys.argv[1:])
|
||||
print("Hai scritto:", frase)
|
25
ex1/b.py
Normal file
25
ex1/b.py
Normal file
@ -0,0 +1,25 @@
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
VALORI_AMMESSI = {"toto", "tata", "titi"}
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
parser.add_argument(
|
||||
'-t', '--target',
|
||||
nargs='+',
|
||||
choices=VALORI_AMMESSI,
|
||||
help="Specifica da 1 a 3 valori tra: toto, tata, titi.",
|
||||
required=True
|
||||
)
|
||||
|
||||
# Esegui parsing
|
||||
args = parser.parse_args()
|
||||
|
||||
# Verifica massimo 3 valori
|
||||
if len(args.target) > 3:
|
||||
print("Errore: puoi fornire **al massimo 3** valori tra 'toto', 'tata' e 'titi'.", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
# Tutto OK
|
||||
print("Valori accettati:", args.target)
|
Loading…
Reference in New Issue
Block a user