Skip to content

Instantly share code, notes, and snippets.

@bricef
bricef / monkey.py
Last active May 16, 2024 03:31
Monkey patching of builtins in Python3
# found this from Armin R. on Twitter, what a beautiful gem ;)
import ctypes
from types import MappingProxyType, MethodType
# figure out side of _Py_ssize_t
if hasattr(ctypes.pythonapi, 'Py_InitModule4_64'):
_Py_ssize_t = ctypes.c_int64
else:
_Py_ssize_t = ctypes.c_int