Python - 检查系统是 32 位还是 64 位以确定是否运行该函数? [英] Python - check if a system is 32 or 64 bit to determine whether to run the function or not?

查看:20
本文介绍了Python - 检查系统是 32 位还是 64 位以确定是否运行该函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
怎么做我确定我的 python shell 是在 32 位还是 64 位模式下执行?

我之前提出了一个从未得到答复的问题,但我现在有一些更具体的问题,希望您能提供帮助.

I made a question earlier that never got replied to, but I have something more specific now so hopefully you can help.

基本上,SendKeys 库似乎只能安装在我的 32 位 Windows 系统上...

Basically the SendKeys library only appears to install on my 32 bit system of Windows...

所以我想知道是否有一种方法可以使我要编写的这个函数只能在 32 位系统上执行?我意识到有一个 platform.architecture() 方法来检查当前系统,但它返回字符串('64bit', 'WindowsPE')".

So I was wondering if there is a way of making it so this function I am going to write will only execute on a 32 bit system? I realise there is a platform.architecture() method to check the current system, but it returns the string "('64bit', 'WindowsPE')".

我想知道是否有办法读取此字符串的 64 位部分以使此函数正常工作.

I was wondering if there was a way to read the 64 bit part of this string to make this function work correctly.

例如伪代码:

checker = platform.architecture()
system = strip or read 64 bit from checker string somehow
if system == 64 bit
then warn system is 64 bit and won't run function
else run function

沿着这条线.除非有更简单的检查方法 - 可能针对使用的 Python 版本(即 32 或 64 位)

Along the line of that. Unless there is a simpler way of checking it - maybe against the version of Python used (ie 32 or 64 bit)

希望我已经正确理解了这一点 - 我对编程还是比较陌生.:)

Hope I've grasped this correctly - I'm still rather new to programming. :)

推荐答案

Following this文档,试试这个代码:

Following this documentation, try this code:

is_64bits = sys.maxsize > 2**32

注意:如果 32 位 Python 在 64 位操作系统上运行,这可能会返回不正确的结果.

Note: this can return an incorrect result if 32bit Python is running on a 64bit operating system.

这篇关于Python - 检查系统是 32 位还是 64 位以确定是否运行该函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆