问题
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. :)
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/9964396/python-check-if-a-system-is-32-or-64-bit-to-determine-whether-to-run-the-funct