How to figure out if the platform is 32bit or 64bit?
Fredrik Lundh
fredrik at pythonware.com
Wed Jul 16 09:55:13 EDT 2008
Ken Hartling wrote:
> Thanks .. but I want to find out if the system is "running on 64bit"
> even when the interpreter is a 32-bit build executable ("what python
> was built on"). platform.architecture() and platform() in general
> seems to only be looking at the build executable
You can pass in an arbitrary binary to architecture(), so I guess you
could use this on some suitable thing under "/bin" on a Unix box. This
doesn't work on Windows, though.
In this message,
http://mail.python.org/pipermail/python-list/2005-June/326158.html
Thomas Heller suggests using ctypes to call the Windows API directly; so
something like this could work:
>>> import ctypes, sys
>>> i = ctypes.c_int()
>>> kernel32 = ctypes.windll.kernel32
>>> process = kernel32.GetCurrentProcess()
>>> kernel32.IsWow64Process(process, ctypes.byref(i))
1
>>> is64bit = (i.value != 0)
>>> is64bit
False
(IsWow64Process returns a non-zero value if it manages to check the
status, and sets the variable to a non-zero value if the process is
running under WOW64. I only have 32-bit boxes here, so it's only
partially tested).
And yes, looks like official support for this might appear in 2.6:
http://mail.python.org/pipermail/python-dev/2008-May/079022.html
(in that thread, Mark Hammond suggests "'64 bit' in sys.version" as a
workaround, but warns for false negatives).
</F>
More information about the Python-list
mailing list