silviubogan silviubogan - 3 years ago 252
Python Question

What are the currently possible values for sys.maxsize?

In the latest Python 2 documentation:


The largest positive integer supported by the platform’s
Py_ssize_t type, and thus the maximum size lists, strings, dicts, and
many other containers can have.

In the latest Python 3 documentation:


An integer giving the maximum value a variable of type
Py_ssize_t can take. It’s usually 2**31 - 1 on a 32-bit platform and
2**63 - 1 on a 64-bit platform.

The value
is in this file used on Python 2 with the values specified in the Python 3 documentation:

  • 2**31 - 1 = 2147483647;

  • 2**63 - 1 = 9223372036854775807.

My question is: what are the possible values
can take in Python 2? Are these two part of the possible values or not? Are there any other possible values (on other platforms or operating systems, for example)? It would be interesting to find the possible values that it can take in Python 3 too.

Related questions:

Answer Source
  • sys.maxsize is telling you something about the C compiler used to compile CPython, so there's no difference between Python 2 and Python 3. It has to do with the C compiler and options that were used, not with the version of Python being compiled.
  • It's the largest positive integer that fits in the platform C compiler's ssize_t type. Which is a 32-bit or 64-bit signed 2's-complement integer on all platforms I've ever seen ;-) Which correspond exactly to the two specific values you already found.
  • It's called type Py_ssize_t in the docs because Python had to create its own typedefs (at the C level) for newer C concepts waiting for all the world's C compilers to implement them. Those Python-specific typedefs typically stick around in the source code even after all known C compilers catch up ("not broke, don't fix").
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download