[Python-ideas] real numbers with SI scale factors: next steps

Chris Angelico rosuav at gmail.com
Tue Aug 30 22:35:24 EDT 2016


On Wed, Aug 31, 2016 at 12:05 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> (5) Is this really something that format() needs to understand? We can
> get a *much* richer and more powerful interface by turning it into a
> generalise numeric pretty-printing library, at the cost of a little less
> convenience.

Or just have a subclass of int or float that defines __format__, and
can do whatever it likes - including specifying the scale, if you so
choose. Say, something like:

{:s} -- autoscale, prefix
{:S} -- autoscale, full word
{:sM} -- scale to mega, print "M"
{:SM} -- scale to mega, print "Mega"
etc

ChrisA


More information about the Python-ideas mailing list