<div class="gmail_quote">On 24 November 2011 03:17, Tom Bennett <span dir="ltr"><<a href="mailto:tom.bennett@mail.zyzhu.net">tom.bennett@mail.zyzhu.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<p>1) In 0.11 and 0.12 we have lost the ability to save macros.</p></blockquote><div>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 always enabled.<br>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><p>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 prompt</p>
</blockquote><div>"%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.<br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<p>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;</p></blockquote><div>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.<br>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><p>2) it is a lot to type "run file args" every single time</p></blockquote>
<div>Try %r <up arrow>.<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><p> </p>
<p>A third way is just to define a python function. For example:</p><p> </p><div>def my_command(param1):<br> s = Object(param1)<br> vw = View(s)<br> vw.show()</div><p> </p><div>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.</div>
</blockquote><div><br>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.<br><br>Hope that helps ;-)<br>Thomas<br>
</div></div><br>