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

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


当前回答

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

import ctypes
print ctypes.sizeof(ctypes.c_voidp)

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

其他回答

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

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

试试这个:

import platform
platform.architecture()
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后

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

import ctypes
print ctypes.sizeof(ctypes.c_voidp)

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

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

import platform
print(platform.architecture())

它给了我

(64bit, 'ELF')