Proposal: Decimal literals in Python.

Ben Finney bignose+hates-spam at benfinney.id.au
Fri Oct 26 11:19:46 CEST 2007


Lennart Benschop <lennartb at xs4all.nl> writes:

> Python has had the Decimal data type for some time now.

Since version 2.4 <URL:http://www.python.org/dev/peps/pep-0327>.

> Unfortunately it is not very easy to access the Decimal data
> type. To obtain the decimal number 12.34 one has to do something
> like this:
> 
> import decimal
> x=decimal.Decimal("12.34")

Slightly nicer, if you need to create a lot of them::

    >>> from decimal import Decimal
    >>> foo = Decimal("12.34")

> Of course we can intruduce a single character function name as an
> alias for the Decimal type constructor, but even then we have to use
> both parentheses and quotes for each and every decimal constant. We
> cannot make it shorter than D("12.34")

Nor should we. A function or type name should be short but explicit,
and 'Decimal' is about as short as I'd want.

> With Python 3000

"Python 3000" is now in beta development, and is called Python version
3.0.

> major changes to the language are carried out anyway.

All of which have been decided for some time now. It's rather too late
to introduce behaviour changes and hope for them to be in Python 3.0.

> My proposal:

Feel free to file an actual proposal using the PEP process. You might
want to refer to the PEP that introduced the Decimal type for
inspiration.

-- 
 \     "How many people here have telekenetic powers? Raise my hand."  |
  `\                                                    -- Emo Philips |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list