Detecting 64bit vs. 32bit Linux

Jim Segrave jes at nl.demon.net
Sat Jul 8 06:04:18 EDT 2006


In article <44aea052$1 at usenet01.boi.hp.com>,
dwelch91  <donald.welch at hp.com> wrote:
>I need to detect whether the operating system I am running on (not the 
>Python version) is 64bit or 32bit. One requirement is that I need to 
>include support for non-Intel/AMD architectures.
>
>The 2 ways I have thought detecting 64bit are:
>
>1. struct.calcsize("P") == 8
>2. '64' in os.uname()[4]
>
>I'm not convinced that either one of these is really adequate. Does 
>anybody have any other ideas on how to do this?

Does sys.maxint give what you need? 

I think for most machines this will give you the answer you are
looking for - either 2**31 -1 for a 32 bit version or 2**63-1 for a 64
bit version. It's set up during the configure phase of building python

If you want to detect a 64bit OS running a compatibility mode for a 32
bit version of Python, then you'll need to figure out how to build and
incorporate a Python extension which can detect this situation




-- 
Jim Segrave           (jes at jes-2.demon.nl)




More information about the Python-list mailing list