[Python-3000] Need Decimal.__format__

Eric Smith eric+python-dev at trueblade.com
Fri Aug 31 14:19:55 CEST 2007


Talin wrote:
> I'm looking for a volunteer who understands the Decimal class well 
> enough to write a __format__ method for it. It should handle all of the 
> same format specifiers as float.__format__, but it should not use the 
> same implementation as float (so as to preserve accuracy.)
> 
> Also, I'm interested in suggestions as to any other standard types that 
> ought to have a __format__ method, other than the obvious Date/Time 
> classes. What kinds of things do people usually want to print?

I have a patch for adding __format__ to datetime, date, and time.  For a 
zero length format_spec, they return str(self), otherwise 
self.strftime(format_spec).

I can whip up some tests and check it in if you want this before a1, but 
if you want more discussion on what it should do then we can wait.  Let 
me know.  But since the deadline is in 40 minutes, I guess we can do it 
for a2.

As for what other types, I can't think of any.  I've scanned through my 
real work code, and int, float, string, and datetime pretty much cover it.

Eric.


More information about the Python-3000 mailing list