How do I determine if my python shell is executing in 32bit or 64bit?

前端 未结 18 1395
北恋
北恋 2020-11-22 04:25

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.<

18条回答
  •  深忆病人
    2020-11-22 04:41

    struct.calcsize("P") returns size of the bytes required to store a single pointer. On a 32-bit system, it would return 4 bytes. On a 64-bit system, it would return 8 bytes.

    So the following would return 32 if you're running 32-bit python and 64 if you're running 64-bit python:

    Python 2

    import struct;print struct.calcsize("P") * 8
    

    Python 3

    import struct;print(struct.calcsize("P") * 8)
    

提交回复
热议问题