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

Python014

如何使用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是几位就是几位系统

只需要一小段python代码,就可以解决用python查询判断系统进程是否存在的操作。具休是怎么样判断进程是不是存在,看下边的python代码就会明白了。

正常我们在编写python代码时,要杀死一个进程之前,一定要做的事情就是要知道这个进程是不是存在,存在要怎么样操作、不存在又怎么样操作。如何查找一个进程是否存在,用Python代码来判断一下最好不过了。

如何用python代码查找一个进程是否存在的源代码如下:

?

12345678910111213141516171819

#-*- coding:utf-8 -*-#编码声明 import win32com.client#导入方法 def check_exsit(process_name): WMI = win32com.client.GetObject('winmgmts:') processCodeCov = WMI.ExecQuery('select * from Win32_Process where Name="%s"' % process_name) if len(processCodeCov) >0:#判断操作 www.iplaypy.comprint '%s is exists' % process_nameelse:print '%s is not exists' % process_name if __name__ == '__main__':check_exsit('chrome.exe')