Skip to main content

Posts

Showing posts from April, 2016

Make Your Own GUI with Python

Suppose you have written a Python script that carries out a simulation based on a physical model and creates a nice plot of the results. Now you wish to explore the model and run the calculation on many different sets of input parameters. What is the best way to proceed? You could write a script that runs the same calculation on a list of inputs that you select ahead of time: inputs = [(x0, y0, z0), (x1, y1, z1), (x2, y2, z2)] for I in inputs: # Insert simulation code here. You could place your script inside a function and call the function repeatedly from the IPython command line with different inputs: def run_simulation(x, y, z): # Insert simulation code here. Both methods work, but neither is ideal. If you use a script with an input list, you have to select the inputs ahead of time. If you find an interesting region of parameter space, you have to modify the script and run it again. If you embed your simulation within a function, you have to do a lot of typing at