0

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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • 1
    an 'uninteractive python instance' is called a python program. It's python source code is the commands the 'instance' went through. – Martijn Pieters Nov 30 '12 at 11:13
  • 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 Nov 30 '12 at 11:45

1 Answers1

0

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.

Community
  • 1
  • 1
tpg2114
  • 14,112
  • 6
  • 42
  • 57
  • Thanks. I was aware of Pickles and the fact that matplotlib objects were not yet fully pickable. Thus the idea to create a "minimum script that can reproduce the graph". "Creating a class that contains all the information you entered" does not seem like a quick and easy (read quick and dirty) way of reaching my goal. – user1866050 Nov 30 '12 at 11:49
  • @user1866050 You may want to put more details in your question to indicate that you are using things like `matplotlib`. There's more than one way to generate a plot. – tpg2114 Nov 30 '12 at 13:53