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