A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-January/051316.html below:

[ 1100942 ] datetime.strptime constructor added

[Python-Dev] Patch review: [ 1100942 ] datetime.strptime constructor addedSkip Montanaro skip at pobox.com
Thu Jan 27 04:17:50 CET 2005
    Alan> 1. In the time module, the strptime() function's format
    Alan> parameter is optional.  For consistency's sake, I'd expect
    Alan> datetime.strptime()'s format parameter also to be optional.  (On
    Alan> the other hand, the default value for the format is not very
    Alan> useful.)

Correct.  No need to propagate a mistake.

    Alan> 2. Since strftime is supported by datetime.time,
    Alan> datetime.date and datetime.datetime, I'd also expect strptime to
    Alan> be supported by all three classes.  Could you add that now, or
    Alan> would it be better to do it as a separate patch?

That can probably be done, but I'm not convinced strftime really belongs on
either date or time objects given the information those objects are missing:

    >>> t = datetime.datetime.now().time()
    >>> t.strftime("%Y-%m-%d")
    '1900-01-01'
    >>> d = datetime.datetime.now().date()
    >>> d.strftime("%H:%M:%S")
    '00:00:00'

I would be happy for strftime to only be available for datetime objects
(assuming there was a good way to get from time or date objects to datetime
objects short of extracting their individual attributes).  In any case,
going from datetime to date or time objects is trivial:

    >>> dt = datetime.datetime.now()
    >>> dt.time()
    datetime.time(21, 12, 18, 705365)

so parsing a string into a datetime object then splitting out date and time
objects seems reasonable.

Skip
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4