I’m in the process of moving some of our internal data visualization/analysis tools from Matlab to IPython/Numpy/Scipy/PyLab. The tools I refer to are Matlab GUIs which do only simple kinds of analysis. Occasionally, I want to do more sophisticated analysis in which case I press a button in the GUI which executes Matlab’s “assignin(‘base’,…”. This puts the data into the top-level session where I can do further operations on it.
This isn’t my only use case for “assignin”. As another example, I’ve also used it to export data for analysis to the main Matlab session from a function deep within some script. (This is just a temporary/debugging trick rather than a routine practice.)
So I ask: Is there an equivalent to Matlab’s assignin when working in an interactive IPython/PyLab environment? If there is no direct equivalent, how can I go about getting data from a script launched from IPython back into the main session?
Take a look at the global namespace. Practically, I’d use something like following code, depending on whether your variable has a static name or the name can change dynamically.
But do note that this might not work across package boundaries!