Steven D'Aprano wrote:

Obviously if I write 1.1K then I'm expecting a float.

Why is it obvious that you're expecting a float and not
a decimal in that case?

The SI units are all decimal, and I think if we support these, we should insist that K == 1000, not 1024. For binary scale factors, there is the IEC standard:

Or perhaps allow the multiplier to be followed by
'b' or 'B' (bits/bytes/binary) to signal a binary scale
factor.

and then there's 1E1E which might be read as 1E1*10**18 or as just an error.

I don't think it's necessary or desirable to support having
both a scale factor *and* an exponent, so I'd go for making
it an error. You can always write 1E * 1E18 etc. if you
need to.

8M  # remains a syntax error
0s8M  # unambiguously an int with a scale factor of M = 10**6

That looks ugly and hard to read to me.

If we're to have that, I'm not sure 's' is the best character,
since it suggest something to do with strings.

Proposal number two: don't make any changes to the syntax, but treat these as *literally* numeric scale factors.
k = kilo = 10**3
M = mega = 10**6
G = giga = 10**9

int_value = 8*M float_value = 8.0*M
fraction_value = Fraction(1, 8)*M
decimal_value = Decimal("1.2345")*M

I like this!

You can even scale by multiple factors:

x = 8*M*K

Which also offers a neat solution to the "floppy megabytes"
problem:

k = 1000
kB = 1024

floppy_size = 1.44*k*kB

--
Greg
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to