How do I determine if my python shell is executing in 32bit or 64bit?
One way is to look at sys.maxsize
as documented here:
$ python-32 -c 'import sys;print("%x" % sys.maxsize, sys.maxsize > 2**32)'('7fffffff', False)$ python-64 -c 'import sys;print("%x" % sys.maxsize, sys.maxsize > 2**32)'('7fffffffffffffff', True)
sys.maxsize
was introduced in Python 2.6. If you need a test for older systems, this slightly more complicated test should work on all Python 2 and 3 releases:
$ python-32 -c 'import struct;print( 8 * struct.calcsize("P"))'32$ python-64 -c 'import struct;print( 8 * struct.calcsize("P"))'64
BTW, you might be tempted to use platform.architecture()
for this. Unfortunately, its results are not always reliable, particularly in the case of OS X universal binaries.
$ arch -x86_64 /usr/bin/python2.6 -c 'import sys,platform; print platform.architecture()[0], sys.maxsize > 2**32'64bit True$ arch -i386 /usr/bin/python2.6 -c 'import sys,platform; print platform.architecture()[0], sys.maxsize > 2**32'64bit False