##// END OF EJS Templates
Documentation update
nfgf -
Show More
@@ -280,7 +280,7 b' def no_var_expand(magic_func):'
280 def output_can_be_silenced(magic_func):
280 def output_can_be_silenced(magic_func):
281 """Mark a magic function so its output may be silenced.
281 """Mark a magic function so its output may be silenced.
282
282
283 The output is silenced if the Python expression used as a parameter of
283 The output is silenced if the Python code used as a parameter of
284 the magic ends in a semicolon, not counting a Python comment that can
284 the magic ends in a semicolon, not counting a Python comment that can
285 follow it.
285 follow it.
286 """
286 """
@@ -139,13 +139,26 b' Accessing user namespace and local scope'
139 ========================================
139 ========================================
140
140
141 When creating line magics, you may need to access surrounding scope to get user
141 When creating line magics, you may need to access surrounding scope to get user
142 variables (e.g when called inside functions). IPython provide the
142 variables (e.g when called inside functions). IPython provides the
143 ``@needs_local_scope`` decorator that can be imported from
143 ``@needs_local_scope`` decorator that can be imported from
144 ``IPython.core.magics``. When decorated with ``@needs_local_scope`` a magic will
144 ``IPython.core.magics``. When decorated with ``@needs_local_scope`` a magic will
145 be passed ``local_ns`` as an argument. As a convenience ``@needs_local_scope``
145 be passed ``local_ns`` as an argument. As a convenience ``@needs_local_scope``
146 can also be applied to cell magics even if cell magics cannot appear at local
146 can also be applied to cell magics even if cell magics cannot appear at local
147 scope context.
147 scope context.
148
148
149 Silencing the magic output
150 ==========================
151
152 Sometimes it may be useful to define a magic that can be silenced the same way
153 that non-magic expressions can, i.e., by appending a semicolon at the end of the Python
154 code to be executed. That can be achieved by decorating the magic function with
155 the decorator ``@output_can_be_silenced`` that can be imported from
156 ``IPython.core.magics``. When this decorator is used, IPython will parse the Python
157 code used by the magic and, if the last token is a ``;``, the output created by the
158 magic will not show up on the screen. If you want to see an example of this decorator
159 in action, take a look on the ``time`` magic defined in
160 ``IPython.core.magics.execution.py``.
161
149 Complete Example
162 Complete Example
150 ================
163 ================
151
164
General Comments 0
You need to be logged in to leave comments. Login now