Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path argument validation in argparse #90

Open
yashpatel6 opened this issue Nov 30, 2023 · 0 comments
Open

Path argument validation in argparse #90

yashpatel6 opened this issue Nov 30, 2023 · 0 comments

Comments

@yashpatel6
Copy link
Collaborator

yashpatel6 commented Nov 30, 2023

It's not a critical point, but for input paths I generally use something like this extant_file type rather than str.

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant