Engineering numerical format PEP discussion

Lie Ryan lie.1296 at gmail.com
Tue Apr 27 11:59:12 CEST 2010


On 04/27/10 10:36, Keith wrote:
> I think it's worth making the print statement (or print function, as
> the case may be) let us do engineering notation, just like it lets us
> specify scientific notation.

The print statement/function does no magic at all in specifying how
numbers look like when. The apparently magical formatting is done by the
%-operator and for {}-style formatting, the obj.__format__().

If you're using the {}-format, you can override .__format__() to define
your own formatting mini-language.

If you need to, you can monkey patch format() so that it wraps int/float
in Engineer wrapper that defines Engineer.__format__() to whatever
formatting style you're using.



More information about the Python-list mailing list