Make verifier use argparse. Not better, but prettier.
This commit is contained in:
parent
88a7a7dece
commit
a81c85eb56
1 changed files with 9 additions and 8 deletions
11
verifier.py
11
verifier.py
|
@ -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:]):
|
||||
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.")
|
||||
except TypeError:
|
||||
raise ValueError(sys.argv[0] + " takes exactly two arguments.")
|
||||
|
|
Loading…
Reference in a new issue