Created
September 10, 2011 11:44
-
-
Save Jach/1208215 to your computer and use it in GitHub Desktop.
Overrides the Python integer five to be equal to four with ctypes magic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import ctypes | |
pyint_p = ctypes.POINTER(ctypes.c_byte*sys.getsizeof(5)) | |
five = ctypes.cast(id(5), pyint_p) | |
print(2 + 2 == 5) # False | |
five.contents[five.contents[:].index(5)] = 4 | |
print(2 + 2 == 5) # True (must be sufficiently large values of 2 there...) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is black magic.