[Python-ideas] %-formatting with Decimals
Nick Coghlan
ncoghlan at gmail.com
Tue Mar 11 23:30:40 CET 2014
On 12 Mar 2014 07:51, <random832 at fastmail.us> wrote:
>
> On Tue, Mar 11, 2014, at 16:25, Ethan Furman wrote:
> > > Is % formatting not going to be updated to support new features
> >
> > No.
> >
> > > or fix bugs like this?
> >
> > It's not a bug. Decimal is not float.
>
> The bug to which I was referring involves not calling __format__ on
> whatever object is passed in as str.format does - Decimal not being
> float is no impediment to str.format and Decimal.__format__ accepting
> the same format strings that float.__format__ does.
>
> > > Is it going to be deprecated?
> >
> > No. %-formatting has its place.
>
> What place is that?
>
> There should be one-- and preferably only one --obvious way to do
> it.
>
> We've got two syntaxes, and two functions, that do _almost_ the same
> thing, but with two completely different microlanguages. Why?
Start by reading PEP 3101, which added str.format to address the
limitations of mod-formatting.
For new users, the recommendation is unconditional: use str.format.
mod-formatting is now a power tool for optimisation, consistency with C
implementations, templating format strings without excessive escaping and
(the main reason it still exists), backwards compatibility (both for
existing code and existing programmers).
The original plan was to eventually deprecate mod-formatting entirely, but
not only did we discover that was harder than expected, we also found it
was actually incredibly useful in some cases to have a formatting system
available that relied on coercion rather than polymorphism, since it could
be faster, was more predictable and also more easily mapped to other
languages like C (especially since Python's mod-formatting is based on C's
printf syntax).
That's why the binary interpolation proposal for 3.5 now *only* proposes
restoring mod-formatting for the binary domain, leaving str.format as a
text domain only operation.
Cheers,
Nick.
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140312/b19fc92a/attachment.html>
More information about the Python-ideas
mailing list