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

bundles / IPython 9.5.0 / IPython / utils / text / SList / fields

function

IPython.utils.text:SList.fields

source: /IPython/utils/text.py :194

Signature

def   fields ( self * fields : List[str] )  →  List[List[str]]

Summary

Collect whitespace-separated fields from string list

Extended Summary

Allows quick awk-like usage of string lists.

Example data (in var a, created by 'a = !ls -l')

-rwxrwxrwx  1 ville None      18 Dec 14  2006 ChangeLog
drwxrwxrwx+ 6 ville None       0 Oct 24 18:05 IPython
  • a.fields(0) is ['-rwxrwxrwx', 'drwxrwxrwx+']

  • a.fields(1,0) is ['1 -rwxrwxrwx', '6 drwxrwxrwx+'] (note the joining by space).

  • a.fields(-1) is ['ChangeLog', 'IPython']

IndexErrors are ignored.

Without args, fields() just split()'s the strings.

Aliases

  • IPython.core.interactiveshell.SList.fields