Skip to content

Instantly share code, notes, and snippets.

@garcia
Created November 2, 2013 22:29
Show Gist options
  • Save garcia/7284193 to your computer and use it in GitHub Desktop.
Save garcia/7284193 to your computer and use it in GitHub Desktop.
Swaps the values of False and True under CPython 2.7.5. Unlike the usual "False, True = True, False" prank, this alters the hardcoded values so that even built-in operations which return a boolean (like 1 == 1) return the opposite.
import ctypes
import sys
for b, boolean in enumerate((False, True)):
(ctypes.c_char * sys.getsizeof(boolean)).from_address(id(boolean))[8] = chr(1 - b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment