12

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

I made a question earlier that never got replied to, but I have something more specific now so hopefully you can help.

Basically the SendKeys library only appears to install on my 32 bit system of Windows...

So I was wondering if there is a way of making it so this function I am going to write will only execute on a 32 bit system? I realise there is a platform.architecture() method to check the current system, but it returns the string "('64bit', 'WindowsPE')".

I was wondering if there was a way to read the 64 bit part of this string to make this function work correctly.

For example, pseudo code:

checker = platform.architecture()
system = strip or read 64 bit from checker string somehow
if system == 64 bit
then warn system is 64 bit and won't run function
else run function

Along the line of that. Unless there is a simpler way of checking it - maybe against the version of Python used (ie 32 or 64 bit)

Hope I've grasped this correctly - I'm still rather new to programming. :)

Community
  • 1
  • 1
Semaj
  • 133
  • 1
  • 1
  • 8
  • 3
    Duplicate of http://stackoverflow.com/questions/1405913/how-do-i-determine-if-my-python-shell-is-executing-in-32bit-or-64bit-mode and http://stackoverflow.com/questions/1842544/how-do-i-detect-if-python-is-running-as-a-64-bit-application and http://stackoverflow.com/questions/2208828/detect-64bit-os-windows-in-python which is probably the most exact duplicate. – agf Apr 01 '12 at 12:37
  • Yes sorry just realised this. The answer below seems the simplest way by far though! – Semaj Apr 01 '12 at 13:20

2 Answers2

22

Following this documentation, try this code:

is_64bits = sys.maxsize > 2**32

Note: this can return an incorrect result if 32bit Python is running on a 64bit operating system.

Marqo09
  • 5
  • 2
Waynn Lue
  • 11,344
  • 8
  • 51
  • 76
6

An alternative method. Definitely works on all platforms:

import struct
is_64bit = struct.calcsize('P') * 8 == 64

As a note, this is part of its.py.

jterrace
  • 64,866
  • 22
  • 157
  • 202
  • 1
    its.py is a no-brainer so you should change its license to PD! I think it would be better to include the tests directly into scripts instead of importing this module. – phobie Sep 26 '12 at 12:18