Issue 852222: builtin save() function available interactively only (original) (raw)
I think that for learning python, it would be nice to save the current namespace to a file using a builtin save() function (and corresponding load(). For beginning programmers, it would be nice to be able to tinker interactively with the shell, defining functions and maybe even classes, with which they can continue later on. save() is easily implemented with pickling locals(); load() is easily implemented with updating locals() while unpickling it. The functions would take a filename (string) as an argument. In Idle, they are in the menu. Like the _ variable, load() and save() are only present in the interactive shell (some global .pythonrc?). I think it would be a useful addition to Python 2.4.
Logged In: YES user_id=80475
Yes, that would be nice but it exceeds the capabilities of pickle which only saves function and class names rather than values:
def f(x, y, z): m = min([x, y, z]) n = max([x, y, z]) p = m * n q = p ** 0.5 return q / y
pickle.dumps(f) 'c__main__\nf\np0\n.'
It may be possible to save the interpreter window as a text file to be replayed later after the prompts and results have been stripped.