[Python-3000] Need Decimal.__format__
Eric Smith
eric+python-dev at trueblade.com
Fri Aug 31 04:03:03 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.)
If no one else steps up, I can look at it. But I doubt I can finish it
by a1.
> 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 can do datetime.datetime and datetime.date, if no one else already
has. I think they're just aliases for strftime. Is there any problem
with re-using the C implemenation exactly?
static PyMethodDef date_methods[] = {
...
{"strftime", (PyCFunction)date_strftime, METH_VARARGS | METH_KEYWORDS,
PyDoc_STR("format -> strftime() style string.")},
{"__format__", (PyCFunction)date_strftime, METH_VARARGS | METH_KEYWORDS,
PyDoc_STR("Alias for strftime.")},
...
I just want to make sure there's no requirement that the function
pointer be unique within the array, or anything like that.
More information about the Python-3000
mailing list