[IPython-User] "extended" macro
Thu Nov 24 04:18:02 CST 2011
On 24 November 2011 03:17, Tom Bennett <firstname.lastname@example.org> wrote:
> 1) In 0.11 and 0.12 we have lost the ability to save macros.
It's back for 0.12, in the 'storemagic' extension. Add that to
c.InteractiveShellApp.extensions in your ipython_config.py file to have it
> 2) Some of my macros are pretty complicated. I would like to be able
> create macros by using an editor insteas of typing them under the command
"%macro mymacro thefile.py" should define a macro from a file. Or I'm sure
it's possible to use %edit and %macro somehow if you prefer.
> An alternative I am thinking about is to use %run file args. The problems
> with that are: 1) the args parameter is quite limited. I cannot pass
> variables to it;
If you call %run -i file, it will be run in your namespace (like a macro),
so it can refer to variables you've already defined.
> 2) it is a lot to type "run file args" every single time
Try %r <up arrow>.
> A third way is just to define a python function. For example:
> def my_command(param1):
> s = Object(param1)
> vw = View(s)
> The problem with this is that I want s and vw to be in the global
> namespace, so that after my_command finishes, I can still play with s and
> vw. So this does not work either.
If you put "global s, vw" at the top of the function, they are put into the
global namespace. That's not IPython magic - it's standard Python.
Hope that helps ;-)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the IPython-User