Issue
According to the docs, I should be able to define a macro and store it. Then, the macro will be available the next time I start the IPython shell. But, it doesn't work:
In [4]: print "Foobarbatbizbuzzbonk"
Foobarbatbizbuzzbonk
In [5]: %macro foo 4
Macro `foo` created. To execute, type its name (without quotes).
=== Macro contents: ===
print "Foobarbatbizbuzzbonk"
In [6]: %store foo
Stored 'foo' (Macro)
In [7]: quit()
When I start the IPython shell again, no macros:
In [1]: foo
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-d3b07384d113> in <module>()
----> 1 foo
NameError: name 'foo' is not defined
In [2]: %macro
Out[2]: []
Does anyone know why this doesn't work?
Solution
I found the answer to this in a couple of obscure places.
First, in the README found in $HOME/.ipython, it says, "For more information on configuring IPython, do: ipython config -h
"
Doing that produces a bunch of help including the following advice:
To initialize a profile with the default configuration file, do::
$> ipython profile create
and start editing `IPYTHONDIR/profile_default/ipython_config.py`
The old docs for this configuration file are here: Configuring the ipython command line application. The latest (as of Jan. 2020) are in the much improved section on Configuration and customization.
Finally, I found my answer in the docs for storemagic [Link updated, Jan. 2020]:
%store magic for lightweight persistence. Stores variables, aliases and macros in IPython’s database. To automatically restore stored variables at startup, add this to your ipython_config.py file:
c.StoreMagics.autorestore = True
Add that, restart IPython and bang! there are my macros. Cool!
Answered By - cbare
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.