Home  >  Article  >  Backend Development  >  python判断windows系统是32位还是64位的方法

python判断windows系统是32位还是64位的方法

WBOY
WBOYOriginal
2016-06-06 11:16:381845browse

本文实例讲述了python判断windows系统是32位还是64位的方法。分享给大家供大家参考。具体分析如下:

通常64的windows系统program files文件夹(用来安装应用程序的默认的默认的目录),有2个,一个是program files另外一个是program files(x86), 而32bit的只有program files这一个文件夹。

根据上面这一特点,我们就可以判断windows系统是32还是64位的。

import os
prg = 'C:Program Files(x86)'
if True == os.path.exists( prg ):
   print '64bit'
else:
  print '32bit'

上面的代码其实是有问题的,如果当前系统是安装在d盘的话就有问题,所以为了完善上面的代码可以判断的一下当前系统的安装盘符,这个可以从系统的环境变量。

另外一种方法,直接使用环境变量:

PROGRAMFILES(X86)
import os
def Is64Windows():
  return 'PROGRAMFILES(X86)' in os.environ

上面的函数判断当前的系统是不是64bit的系统,这个方法就没有第一种方法的问题。

希望本文所述对大家的Python程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn