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

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


当前回答

Windows 10操作系统

打开cmd终端,输入如下图所示的>python启动python解释器

如果解释器信息在开始时包含AMD64,则为64位,否则为32位。

其他回答

Platform.architecture()注释说:

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

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

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

import platform
print(platform.architecture())

它给了我

(64bit, 'ELF')

平台架构不是可靠的方法。 相反,我们:

$ arch -i386 /usr/local/bin/python2.7
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform, sys
>>> platform.architecture(), sys.maxsize
(('64bit', ''), 2147483647)
>>> ^D
$ arch -x86_64 /usr/local/bin/python2.7
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform, sys
>>> platform.architecture(), sys.maxsize
(('64bit', ''), 9223372036854775807)

Windows 10操作系统

打开cmd终端,输入如下图所示的>python启动python解释器

如果解释器信息在开始时包含AMD64,则为64位,否则为32位。

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后