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
17
verifier.py
17
verifier.py
|
@ -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.")
|
||||||
|
|
Loading…
Reference in a new issue