如何使用Python判断当前是32位还是64为操作系统

Python016

如何使用Python判断当前是32位还是64为操作系统,第1张

方法一:

import sys

bit = sys.maxsize

在32位系统中:

bool(bit >2**32) 会输出False

64位中:

bool(bit >2**32)会输出True

方法二(简单粗暴):

import struct

bit = struct.calcsize("P") * 8

print bit

#在这里bit是几位就是几位系统

import platform

def isWindowsSystem():

    return 'Windows' in platform.system()

def isLinuxSystem():

    return 'Linux' in platform.system()

print isWindowsSystem()

print isLinuxSystem()

result:

True

False