codekingpro/portable-devtools
114k
1"""is64bit.Python() --> boolean value of detected Python word size. is64bit.os() --> os build version"""
2import sys
3
4
5def Python():
6 if sys.platform == "cli": # IronPython
7 import System
8
9 return System.IntPtr.Size == 8
10 else:
11 try:
12 return sys.maxsize > 2147483647
13 except AttributeError:
14 return sys.maxint > 2147483647
15
16
17def os():
18 import platform
19
20 pm = platform.machine()
21 if pm != ".." and pm.endswith("64"): # recent Python (not Iron)
22 return True
23 else:
24 import os
25
26 if "PROCESSOR_ARCHITEW6432" in os.environ:
27 return True # 32 bit program running on 64 bit Windows
28 try:
29 return os.environ["PROCESSOR_ARCHITECTURE"].endswith(
30 "64"
31 ) # 64 bit Windows 64 bit program
32 except (IndexError, KeyError):
33 pass # not Windows
34 try:
35 return "64" in platform.architecture()[0] # this often works in Linux
36 except:
37 return False # is an older version of Python, assume also an older os (best we can guess)
38
39
40if __name__ == "__main__":
41 print("is64bit.Python() =", Python(), "is64bit.os() =", os())
42 