Short Integers in Python
Question: Python allocates integers automatically based on the underlying system
architecture. Unfortunately I have a huge dataset which needs to be fully
loaded into memory.

So, is there a way to force Python to use only 2 bytes for some integers
(equivalent of C++ 'short')?


Answer: Nope. But you can use short integers in arrays:

    
    
    from array import array
    a = array("h") # h = signed short, H = unsigned short
    

As long as the value stays in that array it will be a short integer.

  * documentation for the [array module](http://docs.python.org/dev/library/array)

