[issue6316] format, str.format don't work well with datetime, date object

Jeong-Min Lee report at bugs.python.org
Sat Jun 20 17:14:12 CEST 2009


New submission from Jeong-Min Lee <falsetru at gmail.com>:

format(datetime_obj, format_string) return format_string. (when
format_string is not empty.)


>>> import datetime
>>> d = datetime.datetime.now()
>>> format(d)
'2009-06-20 23:51:54.243428'
>>> format(d, '')
'2009-06-20 23:51:54.243428'
>>> d
datetime.datetime(2009, 6, 20, 23, 51, 54, 243428)
>>> '{0}'.format(d)
'2009-06-20 23:51:54.243428'
>>> '{0:30}'.format(d) # odd
'30'
>>> format(d, '30') # odd
'30'
>>> format(str(d), '30') # workaround
'2009-06-20 23:51:54.243428    '
>>> '{0!s:30}'.format(d) # workaround
'2009-06-20 23:51:54.243428    '

----------
components: Extension Modules, Library (Lib)
messages: 89539
nosy: falsetru
severity: normal
status: open
title: format, str.format don't work well with datetime, date object
type: behavior
versions: Python 2.6, Python 2.7, Python 3.0, Python 3.1

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6316>
_______________________________________


More information about the Python-bugs-list mailing list