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.<
Grouping everything...
Considering that:
I'm going to exemplify on all 3 platforms, using Python 3 and Python 2.
0x100000000
(2 ** 32
): greater for 64bit, smaller for 32bit:
>>> import sys >>> "Python {0:s} on {1:s}".format(sys.version, sys.platform) 'Python 2.7.10 (default, Oct 14 2015, 05:51:29) \n[GCC 4.8.2] on darwin' >>> hex(sys.maxsize), sys.maxsize > 0x100000000 ('0x7fffffffffffffff', True)
>>> import sys >>> "Python {0:s} on {1:s}".format(sys.version, sys.platform) 'Python 3.5.2 (default, Nov 23 2017, 16:37:01) \n[GCC 5.4.0 20160609] on linux' >>> hex(sys.maxsize), sys.maxsize > 0x100000000 ('0x7fffffffffffffff', True)
>>> import sys >>> "Python {0:s} on {1:s}".format(sys.version, sys.platform) 'Python 3.6.4 (default, Apr 25 2018, 23:55:56) \n[GCC 5.4.0 20160609] on linux' >>> hex(sys.maxsize), sys.maxsize > 0x100000000 ('0x7fffffff', False)
>>> import sys >>> "Python {0:s} on {1:s}".format(sys.version, sys.platform) 'Python 3.5.4 (v3.5.4:3f56838, Aug 8 2017, 02:17:05) [MSC v.1900 64 bit (AMD64)] on win32' >>> hex(sys.maxsize), sys.maxsize > 0x100000000 ('0x7fffffffffffffff', True)
>>> import sys >>> "Python {0:s} on {1:s}".format(sys.version, sys.platform) 'Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)] on win32' >>> hex(sys.maxsize), sys.maxsize > 0x100000000 ('0x7fffffff', False)
sizeof(void*)
):
>>> import struct >>> struct.calcsize("P") * 8 64
>>> import struct >>> struct.calcsize("P") * 8 64
>>> import struct >>> struct.calcsize("P") * 8 32
>>> import struct >>> struct.calcsize("P") * 8 64
>>> import struct >>> struct.calcsize("P") * 8 32
sizeof(void*)
). As a note, ctypes uses #2. (not necessarily for this task) via "${PYTHON_SRC_DIR}/Lib/ctypes/__init__.py" (around line #15):
>>> import ctypes >>> ctypes.sizeof(ctypes.c_void_p) * 8 64
>>> import ctypes >>> ctypes.sizeof(ctypes.c_void_p) * 8 64
>>> import ctypes >>> ctypes.sizeof(ctypes.c_void_p) * 8 32
>>> import ctypes >>> ctypes.sizeof(ctypes.c_void_p) * 8 64
>>> import ctypes >>> ctypes.sizeof(ctypes.c_void_p) * 8 32
>>> import platform >>> platform.architecture() ('64bit', '')
>>> import platform >>> platform.architecture() ('64bit', 'ELF')
>>> import platform >>> platform.architecture() ('32bit', 'ELF')
>>> import platform >>> platform.architecture() ('64bit', 'WindowsPE')
>>> import platform >>> platform.architecture() ('32bit', 'WindowsPE')
>>> import os >>> os.system("file {0:s}".format(os.path.realpath(sys.executable))) /opt/OPSWbuildtools/2.0.6/bin/python2.7.global: Mach-O 64-bit executable x86_64
>>> import os >>> os.system("file {0:s}".format(os.path.realpath(sys.executable))) /usr/bin/python3.5: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=59a8ef36ca241df24686952480966d7bc0d7c6ea, stripped
>>> import os >>> os.system("file {0:s}".format(os.path.realpath(sys.executable))) /home/cfati/Work/Dev/Python-3.6.4/python: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=5c3d4eeadbd13cd91445d08f90722767b0747de2, not stripped
>>> import os >>> os.environ["PROCESSOR_ARCHITECTURE"] 'AMD64'
>>> import os >>> os.environ["PROCESSOR_ARCHITECTURE"] 'x86'