fork download
  1. import ctypes as c
  2. import sys
  3.  
  4.  
  5. class PyObject_HEAD(c.Structure):
  6. _fields_ = [
  7. ('HEAD', c.c_ubyte * (object.__basicsize__ -
  8. c.sizeof(c.c_void_p))),
  9. ('ob_type', c.c_void_p)
  10. ]
  11.  
  12. _get_dict = c.pythonapi._PyObject_GetDictPtr
  13. _get_dict.restype = c.POINTER(c.py_object)
  14. _get_dict.argtypes = [c.py_object]
  15.  
  16. def get_dict(object):
  17. return _get_dict(object).contents.value
  18.  
  19. get_dict(str)['x'] = 1
  20. print ''.x
  21.  
  22. get_dict(str)['x'] = 2
  23. print ''.x
  24.  
  25. get_dict(str)['y'] = [3]
  26. print ''.y
  27.  
  28. sys.stdout.flush()
  29.  
  30. get_dict(str)['y'] = [4]
  31. print ''.y
Runtime error #stdin #stdout 0.01s 7684KB
stdin
Standard input is empty
stdout
1
1
[3]