Make verifier use argparse. Not better, but prettier.

This commit is contained in:
Klaus-Uwe Mitterer 2015-06-22 19:44:42 +02:00
parent 88a7a7dece
commit a81c85eb56

View file

@ -1,6 +1,6 @@
#!/usr/bin/env python3
import sys
import argparse, sys
def verifier(i1, i2):
try:
@ -11,10 +11,11 @@ def verifier(i1, i2):
raise ValueError("Arguments must be integers.")
if __name__ == "__main__":
try:
if verifier(*sys.argv[1:]):
print("Have fun.")
else:
print("Nope.")
except TypeError:
raise ValueError(sys.argv[0] + " takes exactly two arguments.")
parser = argparse.ArgumentParser()
parser.add_argument("age1", type=int)
parser.add_argument("age2", type=int)
args = parser.parse_args()
if verifier(args.age1, args.age2):
print("Have fun.")
else:
print("Nope.")