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

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


当前回答

在命令行中执行python -VV。它应该返回版本。

其他回答

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

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

试试这个:

import platform
platform.architecture()

根据abe32的回答,

import sys
n_bits = 32 << bool(sys.maxsize >> 32)

N_bits将有32或64位。

尝试使用ctypes来获取void指针的大小:

import ctypes
print ctypes.sizeof(ctypes.c_voidp)

32位是4位,64位是8位。

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后