Skip to content

Instantly share code, notes, and snippets.

@Jach
Created September 10, 2011 11:44
Show Gist options
  • Save Jach/1208215 to your computer and use it in GitHub Desktop.
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
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...)
@peterldowns
Copy link

This is black magic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment