Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python argparse type date

def valid_date(s):
    try:
        return datetime.strptime(s, "%Y-%m-%d")
    except ValueError:
        msg = "Not a valid date: '{0}'.".format(s)
        raise argparse.ArgumentTypeError(msg)

parser.add_argument("-s", 
                    "--startdate", 
                    help="The Start Date - format YYYY-MM-DD", 
                    required=True, 
                    type=valid_date)
Comment

PREVIOUS NEXT
Code Example
Python :: left join outer apply 
Python :: python string to list with separator 
Python :: python dictionary comprehension 
Python :: python range of letters 
Python :: how to use virtual environment python 
Python :: join pandas dataframe by column 
Python :: python divisors 
Python :: matplotlib secondary y axis 
Python :: python abstract method 
Python :: how to use xpath with beautifulsoup 
Python :: iterate through attributes of class python 
Python :: add text to plot python scatter 
Python :: how to change os path in python 
Python :: venv python 
Python :: python aws s3 client 
Python :: power level in google colab 
Python :: factorial program 
Python :: add time to datetime python 
Python :: how to slice even index value from a list in python using slice function 
Python :: factorial in python 
Python :: python version 
Python :: pandas inplace 
Python :: 2 distinct numbers random number generator python 
Python :: pyspark overwrite schema 
Python :: pandas select columns by index 
Python :: npr python 
Python :: python merge two dictionaries in a single expression 
Python :: The Python path in your debug configuration is invalid. 
Python :: template string python 
Python :: distplot with plotly 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =