[issue34249] Full set of format codes applies to strftime only
New submission from v kats <vkatsikaros@gmail.com>: 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' ---------- assignee: docs@python components: Documentation messages: 322498 nosy: docs@python, v kats priority: normal severity: normal status: open title: Full set of format codes applies to strftime only type: enhancement versions: Python 2.7 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34249> _______________________________________
Change by Roundup Robot <devnull@psf.upfronthosting.co.za>: ---------- keywords: +patch pull_requests: +8020 stage: -> patch review _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34249> _______________________________________
v kats <vkatsikaros@gmail.com> added the comment: Note, the last 3 lines of the previous comment seem to be a rogue copy-paste ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34249> _______________________________________
Paul Ganssle <p.ganssle@gmail.com> added the comment: 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. ---------- nosy: +p-ganssle _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34249> _______________________________________
Change by Serhiy Storchaka <storchaka+cpython@gmail.com>: ---------- versions: +Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9 -Python 2.7 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34249> _______________________________________
participants (4)
-
Paul Ganssle
-
Roundup Robot
-
Serhiy Storchaka
-
v kats