[issue7789] Issue using datetime with format()

2010-01-26 Thread JordanS

New submission from JordanS :

format() cannot handle datetime.DateTime objects, returns the format_spec 
instead, without applying formatting to it, perhaps default behaviour in case 
of unknown type. Different modifications, ie: using str.format() syntax produce 
same behaviour.

Sample code: 

import datetime

#data
row = {0: 1, 'BeamId': 218, 2: 0.0, 3: 0.0, 4: datetime.datetime(2006, 7, 18, 
0, 12), 5: datetime.datetime(2007, 2, 23, 18, 26, 55, 45), 6: 
32637.774406455803, 1: 218, 'DateAndTime': datetime.datetime(2007, 2, 23, 18, 
26, 55, 45), 'AvgFlexuralStrengthDown': 32637.774406455803, 'WarmUpTime': 
datetime.datetime(2006, 7, 18, 0, 12), 'AvgFlexuralStrengthUp': 
15916.5463146028, 'IceSheetId': 1, 'Y': 0.0, 'X': 0.0, 7: 15916.5463146028}

titles = ['BeamId', 'DateAndTime', 'AvgFlexuralStrengthDown', 'WarmUpTime', 
'AvgFlexuralStrengthUp', 'IceSheetId', 'Y', 'X']

#attempt to print datetime: ignores formatting, doesn't print datetime value, 
prints format_spec instead
for key in titles:
asLine = "{0:*<30}".format(row[key])
print(asLine),
print '\n'

#prints a repr of datetime
for key in titles:
asLine = "{0!r:*<30}".format(row[key])
print(asLine),
print '\n'

#prints datetime as string
for key in titles:
asLine = "{0!s:*<30}".format(row[key])
print(asLine),
print '\n'

--
components: 2to3 (2.x to 3.0 conversion tool)
messages: 98358
nosy: JordanS
severity: normal
status: open
title: Issue using datetime with format()
type: behavior
versions: Python 2.6, Python 3.1

___
Python tracker 
<http://bugs.python.org/issue7789>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7789] Issue using datetime with format()

2010-01-26 Thread JordanS

JordanS  added the comment:

sorry, first time posting anything like this: 
versions:

Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on 
win32

--

___
Python tracker 
<http://bugs.python.org/issue7789>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com