13

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

2

2 Answers 2

23

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.

Sign up to request clarification or add additional context in comments.

5 Comments

If Python is 32bit and Windows is 64bit, what does this return?
It returns False.
Thanks! This seems to be the solution.
If it's a solution, please mark it as the accepted solution :)
Also, sys.maxsize > 2**31 works.
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.

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.