파이썬 스크립트로 쉘이 32bit인지 64bit인지 알아내려면 어떻게 해야되나요?(OS X)
조회수 2027회
발생하는 문제 및 실행환경
OS X에서 파이썬 스크립트로 쉘이 32bit인지 64bit인지 알아내려면 어떻게 해야되나요?
platform 모듈에는 아키텍쳐같은 정보만 나와있던데
사실 64비트 머신에서는 64비트랑 32비트 둘 다 실행가능하니까 제가 찾는 건 아니더군요..
1 답변
-
2.6이상 - sys.maximize
여기서 갖고 왔습니다.
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
64비트일 때만
sys.maxsize > 2**32
이므로$ 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)
2.5이하 - platform.architecture()
(말씀하신 것처럼 이건 reliable하지 않지만 제가 아는 다른 대안이 없습니다)
$ 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
댓글 입력