How do I find out if a shell is 32bit or 64bit with a Python script? (OSX)

Asked 1 years ago, Updated 1 years ago, 94 views

How do I find out if the shell is 32bit or 64bit with a Python script in OS X?

The platform module has only architectural information

In fact, 64-bit machines can run both 64-bit and 32-bit, so it's not what I'm looking for.

osx python

2022-09-22 13:19

1 Answers

I brought it here .

Note On Mac OS X (and perhaps other platforms), executable files may be universal files containing multiple architectures. To get at the “64-bitness” of the current interpreter, it is more reliable to query the sys.maxsize attribute: is_64bits = sys.maxsize > 2**32

sys.maxsize> 2**32 only when 64-bit, so

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

(As you said, this is not relatable, but there is no alternative I know.)

$ 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


2022-09-22 13:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.