Skip to content

Instantly share code, notes, and snippets.

@sfaleron sfaleron/pybits.py
Last active Jul 27, 2018

Embed
What would you like to do?
Return the "bitness" of the Python interpreter. Generally 32 or 64, but this is not presumed.
"""Presumes that the bitness is a power of two. There have been exceptions,
but they are hopefully securely sealed up in the dustbin of history. I
am not aware of any port of Python to such a platform.
Additionally, systems with fewer than eight bits are not handled correctly.
If you find yourself in such a situation, you are presumed to know better
than to rely on this module."""
def pyBits():
import sys
n = 8
while sys.maxsize > 1<<n:
n <<= 1
return n
def get_bits(pathtoExec):
"""Determine the bitness of an interpreter."""
import subprocess
return subprocess.call([pathtoExec, __file__.replace('pyc', 'py')])
if __name__ == '__main__':
# return the bitness of an interpreter to the parent process
raise SystemExit(pyBits())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.