Skip to content

Instantly share code, notes, and snippets.

@yupbank
Forked from Jach/number_hack.py
Created July 8, 2012 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yupbank/3068942 to your computer and use it in GitHub Desktop.
Save yupbank/3068942 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...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment