idiom to ask if you are on 32 or 64 bit linux platform?

Matt Nordhoff mnordhoff at
Tue Feb 12 08:54:56 CET 2008

Jon wrote:
> Hello everyone,
> I've got a ctypes wrapper to some code which seems to be different
> when compiled on 32 bit linux compared to 64 bit linux. For the
> windows version I can use sys.platform == 'win32' versus 'linux2' to
> decide whether to get the .dll or .so library to load. Having narrowed
> it down to linux I still need to choose between and
> Can someone tell me an idiom to choose the right one?
> Thanks!
> Jon

What about the platform module? platform.architecture() should do it.



>>> import platform
>>> platform.architecture()
('32bit', '')

Note that it analyzes an executable (defaulting to the python
interpreter binary), rather than looking in /proc or something. You
might want to do something like that instead. I guess looking at the
python binary is more accurate on a hybrid 32-bit/64-bit system though..

More information about the Python-list mailing list