I need a way to tell what mode the shell is in from within the shell.
While I'm primarily an OS X user, I'd be interested in knowing about other platforms as well.
I've tried looking at the platform module but it seems only to tell you about "about the bit architecture and the linkage format used for the executable": the binary is compiled as 64bit though (I'm running on OS X 10.6) so it seems to always report 64bit even though I'm using the methods described here to force 32bit mode).
Python Version Bit – Does My Python Shell Run 32 Bit or 64 Bit Version? To check which bit version the Python installation on your operating system supports, simply run the command “ python ” (without quotes) in your command line or PowerShell (Windows), terminal (Ubuntu, macOS), or shell (Linux).
If you are on Windows 7, on a Windows Explorer, right click on the executable and select Properties. At the properties window select the Compatibility tab. If under the Compatibility Mode section you see Windows XP, this is a 32 bit executable. If you see Windows Vista, it is 64 bit.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With