[New-bugs-announce] [issue34249] Full set of format codes applies to strftime only

v kats report at bugs.python.org
Fri Jul 27 11:07:15 EDT 2018


New submission from v kats <vkatsikaros at 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 at python
components: Documentation
messages: 322498
nosy: docs at 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 at bugs.python.org>
<https://bugs.python.org/issue34249>
_______________________________________


More information about the New-bugs-announce mailing list