Skip to content

Instantly share code, notes, and snippets.

@tldrafael
Created November 9, 2020 21:45
Show Gist options
  • Save tldrafael/7362b02796e93efe1733312b61c43445 to your computer and use it in GitHub Desktop.
Save tldrafael/7362b02796e93efe1733312b61c43445 to your computer and use it in GitHub Desktop.
Simple snippet to use argparse
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('-d', type=str, help='directory path', dest='dpath')
parser.add_argument('-f', type=str, help='filepath', dest='fpath')
return parser.parse_args()
if __name__ == '__main__':
args = parse_args()
if not any([args.dpath, args.fpath]):
sys.exit('\tNo arguments provided, check --help')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment