watch this The wheels are turning, slowly turning. home
Python implementation of Smalltalk's "become:" 2004-07-05
Dash and Glyph were explaining what “orthogonal persistence” means to someone in #twisted today. It came up that Python doesn’t have anything like Smalltalk’s “become:”. “become:” replaces all references to one object with a reference to a different object. Of course, I couldn’t let this situation continue.

http://intarweb.us:8080/evil/become.py

It has some problems: it uses hardcoded struct field offsets (I know how to fix this - gather empirical evidence about the proper offsets by twiddling carefully selected values and then examining raw memory - it’s just a question of writing out all the right tests); it doesn’t support all of Python’s types, just enough to make a good example (this is easy to fix, just another question of investing time); it only runs on libc6 systems; and it reads and writes memory directly and manually manages refcounts in some places, so bugs generally lead to segfaults :)

All that said, it works pretty nicely on the types it supports: lists, tuples, dicts (that includes class, instance, and locals), and cells. Not a bad chunk of evil for half an afternoon, I’d say.