kkurian kkurian - 2 months ago 16x
Python Question

python3 strftime output varies by platform


produces results that vary by platform. For example:

OS X 10.10.5

>>> sys.version
'3.5.2 (v3.5.2:4def2a2901a5, Jun 26 2016, 10:47:25) \n[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]'
>>> datetime.datetime(1, 1, 1, 0, 0).strftime('%Y/%m/%d')

Debian 8.5

>>> sys.version
'3.5.2 (default, Aug 12 2016, 16:05:15) \n[GCC 4.9.2]'
>>> datetime.datetime(1, 1, 1, 0, 0).strftime('%Y/%m/%d')

Is this expected behavior? Why?

Jim Jim

strftime is just a thin-wrapper around the strftime function defined in the C library you're using. See a related 'bug' here. This behavior seems to be another case of exactly that.

Differences between the output don't relate to Python since Python will just pass in the arguments and receives the output. Since different platforms have different implementations of the C stdlib, you'll get differing results in some edge cases.