Path argument validation in argparse
Opened this issue · 0 comments
yashpatel6 commented
It's not a critical point, but for input paths I generally use something like this
extant_file
type rather thanstr
.
def extant_file(x):
"""
'Type' for argparse - checks that file exists but does not open.
"""
if not os.path.exists(x):
# Argparse uses the ArgumentTypeError to give a rejection message like:
# error: argument input: x does not exist
raise argparse.ArgumentTypeError("{0} does not exist".format(x))
return x
Originally posted by @nwiltsie in #88 (comment)