我怎么能从壳内告诉壳处于什么模式?

我已经试着查看了平台模块,但它似乎只告诉您“用于可执行文件的位架构和链接格式”。我的二进制文件被编译为64位(我在OS X 10.6上运行),所以它似乎总是报告64位,即使我使用这里描述的方法强制32位模式。


当前回答

在我的Centos Linux系统上,我做了以下操作: 1)启动Python解释器(我使用2.6.6) 2)运行如下代码:

import platform
print(platform.architecture())

它给了我

(64bit, 'ELF')

其他回答

C:\Users\xyz>python

Python 2.7.6 (default, Nov XY ..., 19:24:24) **[MSC v.1500 64 bit (AMD64)] on win
32**
Type "help", "copyright", "credits" or "license" for more information.
>>>

在CMD中点击python后

基本上是Matthew Marshall答案的变体(使用来自std.library的struct):

import struct
print struct.calcsize("P") * 8

Platform.architecture()注释说:

注意: 在Mac OS X(也许还有其他平台)上,可执行文件可能是包含多种体系结构的通用文件。 为了获得当前解释器的“64位”,它更可靠 查询sys. xml文件。最大尺寸属性:

import sys
is_64bits = sys.maxsize > 2**32

struct.calcsize("P")返回存储单个指针所需的字节大小。在32位系统上,它将返回4个字节。在64位系统上,它将返回8个字节。

因此,如果你运行的是32位的python,则返回32;如果你运行的是64位的python,则返回64:

Python 2

import struct;print struct.calcsize("P") * 8

Python 3

import struct;print(struct.calcsize("P") * 8)

对于非编程解决方案,请查看活动监视器。它将64位进程的体系结构列为“Intel(64位)”。