How do I detect if Python is running as a 64-bit application?

Nick Bolton picture Nick Bolton · Dec 3, 2009 · Viewed 143.1k times · Source

Possible Duplicate:
How do I determine if my python shell is executing in 32bit or 64bit mode?

I'm doing some work with the windows registry. Depending on whether you're running python as 32-bit or 64-bit, the key value will be different. How do I detect if Python is running as a 64-bit application as opposed to a 32-bit application?

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

Answer

Cristian picture Cristian · Dec 3, 2009
import platform
platform.architecture()

From the Python docs:

Queries the given executable (defaults to the Python interpreter binary) for various architecture information.

Returns a tuple (bits, linkage) which contain information about the bit architecture and the linkage format used for the executable. Both values are returned as strings.