Skip to content

Instantly share code, notes, and snippets.

@sakurai-youhei
Last active January 22, 2018 01:26
Show Gist options
  • Save sakurai-youhei/662dfc5d72b7a57f7fa828270a712a4d to your computer and use it in GitHub Desktop.
Save sakurai-youhei/662dfc5d72b7a57f7fa828270a712a4d to your computer and use it in GitHub Desktop.
memoryview-like Python object view
from ctypes import c_ubyte
from ctypes import cast
from ctypes import POINTER
from sys import getsizeof
def objview(obj):
return cast(id(obj), POINTER(c_ubyte * getsizeof(obj))).contents
'''
def balus():
"""Word to let your interpreter crash"""
objview(1)[-4:] = 0, 0, 0, 0
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment