##// END OF EJS Templates
Give the example for custom magics in the docs....
Matthias Bussonnier -
Show More
@@ -84,12 +84,17 b' IPython object:'
84 84
85 85
86 86 # In order to actually use these magics, you must register them with a
87 # running IPython. This code must be placed in a file that is loaded once
88 # IPython is up and running:
89 ip = get_ipython()
90 # You can register the class itself without instantiating it. IPython will
91 # call the default constructor on it.
92 ip.register_magics(MyMagics)
87 # running IPython.
88
89 def load_ipython_extension(ipython):
90 """
91 Any nodule file that define a function named load_ipython_extension can
92 be loaded via `load_ext` or be configured to be autoloaded by IPython at
93 startup time.
94 """
95 # You can register the class itself without instantiating it. IPython will
96 # call the default constructor on it.
97 ipython.register_magics(MyMagics)
93 98
94 99 If you want to create a class with a different constructor that holds
95 100 additional state, then you should always call the parent constructor and
@@ -108,11 +113,16 b' instantiate the class yourself before registration:'
108 113
109 114 # etc...
110 115
111 # This class must then be registered with a manually created instance,
112 # since its constructor has different arguments from the default:
113 ip = get_ipython()
114 magics = StatefulMagics(ip, some_data)
115 ip.register_magics(magics)
116 def load_ipython_extension(ipython):
117 """
118 Any nodule file that define a function named load_ipython_extension can
119 be loaded via `load_ext` or be configured to be autoloaded by IPython at
120 startup time.
121 """
122 # This class must then be registered with a manually created instance,
123 # since its constructor has different arguments from the default:
124 magics = StatefulMagics(ip, some_data)
125 ipython.register_magics(magics)
116 126
117 127
118 128 .. note::
General Comments 0
You need to be logged in to leave comments. Login now