classification
Title: Full set of format codes applies to strftime only
Type: enhancement Stage: patch review
Components: Documentation Versions: Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, p-ganssle, v kats
Priority: normal Keywords: patch

Created on 2018-07-27 15:07 by v kats, last changed 2019-04-11 18:50 by p-ganssle.

Pull Requests
URL Status Linked Edit
PR 8502 open python-dev, 2018-07-27 15:08
Messages (3)
msg322498 - (view) Author: v kats (v kats) * Date: 2018-07-27 15:07
Section "strftime() and strptime() Behavior" says:

"The full set of format codes supported varies across platforms, because Python calls the platform C library’s strftime() function, and platform variations are common. To see the full set of format codes supported on your platform, consult the strftime(3) documentation."

It implies that this applies for strftime only, and indeed it refers to C library’s strftime().

However, it's easy to miss (at least I got confused and lost some time), so I propose to clarify the paragraph.

strptime and %s

# python
Python 2.7.6 (default, Nov 23 2017, 15:49:48) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import datetime
>>> datetime.strptime('1532689414','%s')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>


strftime and %s

python
Python 2.7.6 (default, Nov 23 2017, 15:49:48) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import datetime
>>> datetime.now().strftime('%s')
'1532702817'

  File "/usr/lib/python2.7/_strptime.py", line 317, in _strptime
    (bad_directive, format))
ValueError: 's' is a bad directive in format '%s'
msg322499 - (view) Author: v kats (v kats) * Date: 2018-07-27 15:19
Note, the last 3 lines of the previous comment seem to be a rogue copy-paste
msg339993 - (view) Author: Paul Ganssle (p-ganssle) * (Python committer) Date: 2019-04-11 18:50
To clarify, as far as I know, this note *does* apply to both strftime and strptime, as CPython doesn't have its own implementation of either. I'm not sure if any guarantees are made that the supported formatting codes will be the same between the two.
History
Date User Action Args
2019-04-11 18:50:28p-gansslesetnosy: + p-ganssle
messages: + msg339993
2018-07-27 15:19:22v katssetmessages: + msg322499
2018-07-27 15:08:05python-devsetkeywords: + patch
stage: patch review
pull_requests: + pull_request8020
2018-07-27 15:07:15v katscreate