Thanks for the suggestions Daniel. I've since discovered an equivalent to PHP's register_shutdown_function() as follows: def myFunc (): """ perform cleanup just before the script exits """ import atexit atexit.register(myFunc) The var_export equivalent however, is much more tricky. I'm going to post a more specific thread concerning it's difficulties. - Kevin