0
votes

I know the python interpreter and ipython have a easy way to browse through the history of commands. That is in interactive Python programming.

My problem/question: I have a GUI-based Python tool that allows me to click and enter values in fields before hitting the "PLOT" button and I get a plot on screen. What I am looking for is a way to access a "minimimum script" that exactly reproduces the plot.

So I was wondering if there was a way to request a backlog of all the commands an uninteractive Python instance went through.

If it is not built-in, could someone advise a way to automatically dump function calls in a file at the same time as they are run.

1
an 'uninteractive python instance' is called a python program. It's python source code is the commands the 'instance' went through. - Martijn Pieters
I agree Martijn. Maybe my choice of words was not the best. But note I have a GUI-based tool, and what I would like is a way to generate a (smaller) source code that only lists the function calls it went through, without all the clicking and editing... - user1866050

1 Answers

0
votes

The simplest way to do that would be to Pickle your plot object. Then you can just reload the pickle file and the object will be in memory just as it was when dumped.

It should only take a couple of lines to implement a dump and reload feature in your program.

This of course doesn't give you a list of commands or anything like that to regenerate the figure, but it does give you the exact state of the object.

If you are using matplotlib to do the plotting, then the image itself is not picklable. But you could create a class that contains all the information you entered that is passed to the matplotlib routines and pickle that, again saving the state.