Last active
July 8, 2020 06:00
-
-
Save vinodjayachandran/8074dbb055b573d79e3a95bc37808402 to your computer and use it in GitHub Desktop.
Fetch named command line arguments in Python Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
parser = argparse.ArgumentParser() | |
# String Argument | |
parser.add_argument('-c','--compName', type=str, metavar='compName', help='Competitor name as Input', required=True); | |
# Optional Integer Arguement, | |
parser.add_argument('-l','--limit', type=int, metavar='limit', help='Number of recrods to fetch', required=False); | |
# Date arguement with format validation | |
def lambda_date_args(s): | |
if(s is not None or s != '' ): | |
return datetime.strptime(s, '%Y-%m-%d') | |
parser.add_argument('-s','--startDate', type=lambda_date_args, metavar='startDate', help='Start Date as Input', required=False); | |
# Extracting the parameters | |
args = parser.parse_args() | |
compName = args.compName | |
limit = args.limit | |
startDate = args.startDate | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment