How to determine if Python works as a 64-bit application?

Possible duplicate:
How to determine whether my python shell is performed in 32-bit or 64-bit mode?

I am working with a windows registry. Depending on whether you are using python as a 32-bit or 64-bit key value will be different. How to determine if Python is working as a 64-bit application, rather than a 32-bit application?

Note. I'm not interested in the detection of 32-bit / 64-bit Windows - just Python platform.

+71
python 64bit
Dec 03 '09 at 20:06
source share
3 answers
import platform platform.architecture() 

From Python Docs :

It will query this executable file (the default for the Python binary interpreter) for various architecture information.

Returns a tuple (bit, link) that contains information about the bit architecture and link format used for the executable. Both values ​​are returned as strings.

+124
Dec 03 '09 at 20:12
source share

Although it may work on some platforms, keep in mind that platform.architecture not always a reliable way to determine if python works in 32-bit or 64-bit. In particular, on some OS X multi-line architectures, the same executable file can work in any mode, as shown in the example below. The fastest secure multi-platform approach is to check sys.maxsize on Python 2.6, 2.7, Python 3.x.

 $ 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) ), $ 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) 
+47
Dec 03 '09 at 20:30
source share
+4
Dec 03 '09 at 20:13
source share



All Articles