Skip to content

Instantly share code, notes, and snippets.

@sfaleron
Last active July 27, 2018 15:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sfaleron/6d31cfe2a7188b6bcea5ca67346254a1 to your computer and use it in GitHub Desktop.
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