##// END OF EJS Templates
Improve documentation for extensions, and for storemagic extension.
Thomas Kluyver -
Show More
@@ -0,0 +1,8 b''
1 .. _extensions_storemagic:
2
3 ==========
4 storemagic
5 ==========
6
7 .. automodule:: IPython.extensions.storemagic
8 :members: magic_store
@@ -2000,14 +2000,16 b' class InteractiveShell(SingletonConfigurable, Magic):'
2000 2000
2001 2001 def define_magic(self, magicname, func):
2002 2002 """Expose own function as magic function for ipython
2003
2004 Example::
2003 2005
2004 def foo_impl(self,parameter_s=''):
2005 'My very own magic!. (Use docstrings, IPython reads them).'
2006 print 'Magic function. Passed parameter is between < >:'
2007 print '<%s>' % parameter_s
2008 print 'The self object is:',self
2006 def foo_impl(self,parameter_s=''):
2007 'My very own magic!. (Use docstrings, IPython reads them).'
2008 print 'Magic function. Passed parameter is between < >:'
2009 print '<%s>' % parameter_s
2010 print 'The self object is:', self
2009 2011
2010 self.define_magic('foo',foo_impl)
2012 ip.define_magic('foo',foo_impl)
2011 2013 """
2012 2014 im = types.MethodType(func,self)
2013 2015 old = getattr(self, "magic_" + magicname, None)
@@ -2,16 +2,18 b''
2 2 """
3 3 %store magic for lightweight persistence.
4 4
5 Stores variables, aliases etc. in PickleShare database.
5 Stores variables, aliases and macros in IPython's database. Stored values will
6 be automatically restored whenever the extension is loaded.
6 7
7 To enable this functionality, run::
8 To enable this functionality, list it in your default profile
9 `ipython_config.py` file::
8 10
9 %load_ext storemagic
11 c.InteractiveShellApp.extensions = ['storemagic']
10 12
11 in your IPython session. If you always want it enabled, you can list it in
12 your default profile `ipython_config.py` file::
13 Or to use it temporarily, run this in your IPython session::
14
15 %load_ext storemagic
13 16
14 c.InteractiveShellApp.extensions = ['storemagic']
15 17 """
16 18
17 19 from IPython.core.error import TryNext, UsageError
@@ -54,34 +56,33 b' def restore_data(ip):'
54 56 def magic_store(self, parameter_s=''):
55 57 """Lightweight persistence for python variables.
56 58
57 Example:
58
59 ville@badger[~]|1> A = ['hello',10,'world']\\
60 ville@badger[~]|2> %store A\\
61 ville@badger[~]|3> Exit
59 Example::
62 60
63 (IPython session is closed and started again...)
61 In [1]: l = ['hello',10,'world']
62 In [2]: %store l
63 In [3]: exit
64 64
65 ville@badger:~$ ipython -p pysh\\
66 ville@badger[~]|1> print A
65 (IPython session is closed and started again...)
67 66
68 ['hello', 10, 'world']
67 ville@badger:~$ ipython
68 In [1]: l
69 Out[1]: ['hello', 10, 'world']
69 70
70 71 Usage:
71 72
72 %store - Show list of all variables and their current values\\
73 %store <var> - Store the *current* value of the variable to disk\\
74 %store -d <var> - Remove the variable and its value from storage\\
75 %store -z - Remove all variables from storage\\
76 %store -r - Refresh all variables from store (delete current vals)\\
77 %store foo >a.txt - Store value of foo to new file a.txt\\
78 %store foo >>a.txt - Append value of foo to file a.txt\\
73 * ``%store`` - Show list of all variables and their current values
74 * ``%store spam`` - Store the *current* value of the variable spam to disk
75 * ``%store -d spam`` - Remove the variable and its value from storage
76 * ``%store -z`` - Remove all variables from storage
77 * ``%store -r`` - Refresh all variables from store (delete current vals)
78 * ``%store foo >a.txt`` - Store value of foo to new file a.txt
79 * ``%store foo >>a.txt`` - Append value of foo to file a.txt
79 80
80 81 It should be noted that if you change the value of a variable, you
81 82 need to %store it again if you want to persist the new value.
82 83
83 84 Note also that the variables will need to be pickleable; most basic
84 python types can be safely %stored.
85 python types can be safely %store'd.
85 86
86 87 Also aliases can be %store'd across sessions.
87 88 """
@@ -29,6 +29,10 b' The :func:`load_ipython_extension` will be called again is you load or reload'
29 29 the extension again. It is up to the extension author to add code to manage
30 30 that.
31 31
32 Useful :class:`InteractiveShell` methods include :meth:`~IPython.core.interactiveshell.InteractiveShell.define_magic`,
33 :meth:`~IPython.core.interactiveshell.InteractiveShell.push` (to add variables to the user namespace) and
34 :meth:`~IPython.core.interactiveshell.InteractiveShell.drop_by_id` (to remove variables on unloading).
35
32 36 You can put your extension modules anywhere you want, as long as they can be
33 37 imported by Python's standard import mechanism. However, to make it easy to
34 38 write extensions, you can also put your extensions in
@@ -68,4 +72,5 b' Extensions bundled with IPython'
68 72
69 73 autoreload
70 74 parallelmagic
75 storemagic
71 76 sympyprinting
@@ -62,7 +62,7 b' New features'
62 62 Terminal frontend by default (:ghpull:`838`).
63 63
64 64 * **%store**: The ``%store`` magic from earlier versions has been updated and
65 placed in an extension, 'storemagic'. Add 'storemagic' to ``c.InteractiveShellApp.extensions``
65 placed in an extension, :ref:`extensions_storemagic`. Add 'storemagic' to ``c.InteractiveShellApp.extensions``
66 66 in ipython_config.py to enable it (:ghpull:`1029`).
67 67
68 68
General Comments 0
You need to be logged in to leave comments. Login now