Skip to content

Instantly share code, notes, and snippets.

@scottmcgowan
scottmcgowan / clear_string.py
Created December 15, 2016 21:26
Python clear string variable
import sys
import ctypes
def clear_string(string, debug=False):
buffer_size = len(string) + 1 # Add 1 for null terminator
header_offset = sys.getsizeof(string) - buffer_size
location = id(string) + header_offset
if debug:
print('Original string: {}'.format(repr(string)))

Keybase proof

I hereby claim:

  • I am scottmcgowan on github.
  • I am scottmcgowan (https://keybase.io/scottmcgowan) on keybase.
  • I have a public key whose fingerprint is 33C9 AA39 7580 356A F844 42CA 00D6 E30B 965C 5B5C

To claim this, I am signing this object: