Rationale for core Python numeric types

Miki Tebeka miki.tebeka at zoran.com
Thu Jun 17 08:39:13 EDT 2004


Hello Matt,

> I'm new to Python, and was somewhat taken aback to discover that the
> core language lacks some basic numerical types (e.g., single-precision
> float, short integers). I realize that there are extensions that add
> these types-- But what's the rationale for leaving them out? Have I
> wandered into a zone in the space/time continuum where people never
> have to read binary data files?
I think the reason most types were left out is that they are machine
specific and Python tries to be as cross platform as it can. I'm sure Tim
will have more on the subject ;-)

I work *a lot* with binary files and don't find these missing types any
problem.  Python provides good access to binary data with `array' and `sturct'
modules.

If I need some bounded number the following class is enough:
class SizedNum:
    def __init__(self, size, value=0):
        self.mask = (1 << size) - 1
        self.set(value)

    def set(self, value):
        self.value = value & self.mask

You can get fancier by sub-classing long type.

Maybe you can be more specific on *why* do you need these types.
IIRC a rational type is about to be added.

Bye.
--
-------------------------------------------------------------------------
Miki Tebeka <miki.tebeka at zoran.com>
The only difference between children and adults is the price of the toys.




More information about the Python-list mailing list