You are viewing an older version (9.5.0). Go to latest (9.13.0)
{ } Raw JSON

bundles / IPython 9.5.0 / IPython / core / magics / osm / OSMagics / sx

function

IPython.core.magics.osm:OSMagics.sx

source: /IPython/core/magics/osm.py :680

Signature

def   sx ( self line = '' cell = None )

Summary

Shell execute - run shell command and capture output (!! is short-hand).

Extended Summary

%sx command

IPython will run the given command using commands.getoutput(), and return the result formatted as a list (split on 'n'). Since the output is _returned_, it will be stored in ipython's regular output cache Out[N] and in the '_N' automatic variables.

Notes:

  • If an input line begins with '!!', then %sx is automatically

invoked. That is, while

!ls

causes ipython to simply issue system('ls'), typing

!!ls

is a shorthand equivalent to

%sx ls
  • %sx differs from %sc in that %sx automatically splits into a list,

like '%sc -l'. The reason for this is to make it as easy as possible to process line-oriented shell output via further python commands. %sc is meant to provide much finer control, but requires more typing.

.l(or.list)

.l (or .list)

This is very useful when trying to use such lists as arguments to system commands.

Aliases

  • IPython.core.magics.OSMagics.sx