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

Matt Nordhoff mnordhoff at mattnordhoff.com
Tue Feb 12 02:54:56 EST 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 libKLT32.so and
> libKLT64.so
> 
> Can someone tell me an idiom to choose the right one?
> 
> Thanks!
> 
> Jon

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

<http://docs.python.org/lib/module-platform.html>

<http://docs.python.org/lib/node442.html#l2h-3157>

>>> 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