There is a representation for decimal literals that nicely avoids the problem of remembering that 0d is decimal and 0m is meters etc.:<br>
<br>
<div style="margin-left: 40px;">>>> import decimal<br>
>>> decimal.Decimal(3)<br>
Decimal("3")<br>
>>> <span style="background-color: rgb(255, 255, 153);">Decimal("3")</span><br>
Traceback (most recent call last):<br>
  File "<stdin>", line 1, in ?<br>
NameError: name 'Decimal' is not defined<br>
</div>
<br>The error points out that I really need to do both:<br><br><div style="margin-left: 40px;">>>> import decimal<br>>>> from decimal import Decimal. <br></div><br>and I'd prefer the single import do both. Note that this anomaly of repr is not limited to decimal as I think this is a bit worse:<br>

<br>
<div style="margin-left: 40px;">>>> float('nan')<br>
nan<br>
>>> float('inf')<br>
inf<br>
</div><br>--- Bruce<br><br><div class="gmail_quote">On Fri, Dec 5, 2008 at 10:53 AM, Jim Jewett <span dir="ltr"><<a href="mailto:jimjjewett@gmail.com">jimjjewett@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Thu, Dec 4, 2008 at 4:45 AM, Cesare Di Mauro<br>
<div class="Ih2E3d"><<a href="mailto:cesare.dimauro@a-tono.com">cesare.dimauro@a-tono.com</a>> wrote:<br>
</div><div class="Ih2E3d">> But at least it will be more usable to have a<br>
> short-hand for decimal declaration:<br>
<br>
</div>In isolation, a decimal literal sounds nice.<br>
<br>
But it may not be used often enough to justify the extra mental complexity.<br>
<br>
What should the following mean?<br>
<br>
>>> a = 123X<br>
<br>
It isn't obvious, which means that either it gets used all the time<br>
(decimal won't) or people will have to look it up -- or just guess,<br>
and sometimes get it wrong.<br>
<br>
> a = 1234.567d<br>
<br>
To someone who hasn't programmed much with decimal floating point,<br>
what does the "d" mean?<br>
<br>
Could it indicate "use double-precision"?<br>
<br>
Could it just mean that the written representation is "decimal" as<br>
opposed to "octal" or "hexadecimal", but that the internal form is<br>
still binary?<br>
<br>
> a = 1234.567d<br>
<br>
> is simpler than:<br>
<br>
[reworded to be even shorter per use]<br>
<br>
>>> from decimal import Decimal as d<br>
>>> a = d('1234.5678')<br>
<br>
but if you really have enough Decimal literals for the difference to<br>
matter, you could always write your own helper function.<br>
<br>
>>> # pretend to be using the European decimal point<br>
>>> a = d(1234,5678)<br>
<br>
>>> # maps easily to the tuple-format constructor<br>
>>> a = d(12345678, -4)<br>
<br>
My own hunch is that until Decimal is used enough that people start<br>
putting this sort of constructor into their personal libraries, it<br>
probably doesn't need a literal.<br>
<font color="#888888"><br>
-jJ<br>
</font><div><div></div><div class="Wj3C7c">_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/mailman/listinfo/python-ideas</a><br>
</div></div></blockquote></div><br>