Last active
July 27, 2018 15:45
Star
You must be signed in to star a gist
Return the "bitness" of the Python interpreter. Generally 32 or 64, but this is not presumed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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