Message240220
Hello,
Reasonably frequently I find myself needing to pass a date as a command line argument to a Python script I've written. Currently, argparse does not have a built support for dates - this adds a new class to argparse (much like the existing FileType) that parses arguments to datetime.date instances.
Example:
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('--start', type=argparse.DateType('%d/%m/%Y))
>>> parser.add_argument('end', type=argparse.DateType())
>>> parser.parse_args(['--start', '01/02/2015', '2015-01-03'])
Namespace(end=datetime.date(2015, 1, 3), start=datetime.date(2015, 1, 2))
I think this would be a useful addition to the standard library, a quick Google shows that many people roll their own version of this anyway.
Support for datetime.datetime and perhaps even datetime.timedeltas might be good too, but date/times get a bit more complicated (timezones in general and varying support for the '%z' format string which is required to default to an ISO8601 date time).
Cheers,
Pete |
|
Date |
User |
Action |
Args |
2015-04-07 17:29:13 | petedmarsh | set | recipients:
+ petedmarsh |
2015-04-07 17:29:13 | petedmarsh | set | messageid: <1428427753.85.0.794213637884.issue23884@psf.upfronthosting.co.za> |
2015-04-07 17:29:13 | petedmarsh | link | issue23884 messages |
2015-04-07 17:29:13 | petedmarsh | create | |
|