##// END OF EJS Templates
Update reference.rst...
Kyle Rawlins -
Show More
@@ -145,6 +145,10 b' use it:'
145
145
146 /home/fperez/ipython
146 /home/fperez/ipython
147
147
148 Line magics, if they return a value, can be assigned to a variable using the syntax
149 ``l = %sx ls`` (which returns the result of `ls` as a python list). See :ref:`below <manual_capture>`
150 for more information.
151
148 Type ``%magic`` for more information, including a list of all available magic
152 Type ``%magic`` for more information, including a list of all available magic
149 functions at any time and their docstrings. You can also type
153 functions at any time and their docstrings. You can also type
150 ``%magic_function_name?`` (see :ref:`below <dynamic_object_info>` for
154 ``%magic_function_name?`` (see :ref:`below <dynamic_object_info>` for
@@ -356,16 +360,22 b' Any input line beginning with a ! character is passed verbatim (minus'
356 the !, of course) to the underlying operating system. For example,
360 the !, of course) to the underlying operating system. For example,
357 typing ``!ls`` will run 'ls' in the current directory.
361 typing ``!ls`` will run 'ls' in the current directory.
358
362
359 Manual capture of command output
363 .. _manual_capture:
360 --------------------------------
361
364
362 You can assign the result of a system command to a Python variable with the
365 Manual capture of command output and magic output
363 syntax ``myfiles = !ls``. This gets machine readable output from stdout
366 -------------------------------------------------
364 (e.g. without colours), and splits on newlines. To explicitly get this sort of
365 output without assigning to a variable, use two exclamation marks (``!!ls``) or
366 the :magic:`sx` magic command.
367
367
368 The captured list has some convenience features. ``myfiles.n`` or ``myfiles.s``
368 You can assign the result of a system command to a Python variable with the
369 syntax ``myfiles = !ls``. Similarly, the result of a magic (as long as it returns
370 a value) can be assigned to a variable. For example, the syntax ``myfiles = %sx ls``
371 is equivalent to the above system command example (the :magic:`sx` runs a shell command
372 and captures the output). Each of these gets machine
373 readable output from stdout (e.g. without colours), and splits on newlines. To
374 explicitly get this sort of output without assigning to a variable, use two
375 exclamation marks (``!!ls``) or the :magic:`sx` magic command without an assignment.
376 (Note that ``!!`` commands cannot be assigned to a variable.)
377
378 The captured list in this example has some convenience features. ``myfiles.n`` or ``myfiles.s``
369 returns a string delimited by newlines or spaces, respectively. ``myfiles.p``
379 returns a string delimited by newlines or spaces, respectively. ``myfiles.p``
370 produces `path objects <http://pypi.python.org/pypi/path.py>`_ from the list items.
380 produces `path objects <http://pypi.python.org/pypi/path.py>`_ from the list items.
371 See :ref:`string_lists` for details.
381 See :ref:`string_lists` for details.
General Comments 0
You need to be logged in to leave comments. Login now