function.var-export

function.var-export

[code=python] ¶
# This seems to work ok ¶
def var_export(self, obj, ret_val = False) : ¶
import os,sys,pprint ¶
if ret_val == False : ¶
pprint.pprint(obj) ¶
return None ¶
fn = '/path/to/temp/file' ¶
temp = sys.stdout # store original stdout object for later ¶
sys.stdout = open(fn, 'w') # redirect all prints to temp file ¶
pprint.pprint(obj) ¶
sys.stdout.close() ¶
sys.stdout = temp # restore print commands to interactive prompt ¶
return open(fn, 'r').read() ¶
[/code]