MCPcopy Create free account
hub / github.com/ipython/ipython / fields

Method fields

IPython/utils/text.py:167–201  ·  view source on GitHub ↗

Collect whitespace-separated fields from string list 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 IPyth

(self, *fields)

Source from the content-addressed store, hash-verified

165 return SList([el for el in self if not pred(match_target(el))])
166
167 def fields(self, *fields):
168 """ Collect whitespace-separated fields from string list
169
170 Allows quick awk-like usage of string lists.
171
172 Example data (in var a, created by 'a = !ls -l')::
173
174 -rwxrwxrwx 1 ville None 18 Dec 14 2006 ChangeLog
175 drwxrwxrwx+ 6 ville None 0 Oct 24 18:05 IPython
176
177 * ``a.fields(0)`` is ``['-rwxrwxrwx', 'drwxrwxrwx+']``
178 * ``a.fields(1,0)`` is ``['1 -rwxrwxrwx', '6 drwxrwxrwx+']``
179 (note the joining by space).
180 * ``a.fields(-1)`` is ``['ChangeLog', 'IPython']``
181
182 IndexErrors are ignored.
183
184 Without args, fields() just split()'s the strings.
185 """
186 if len(fields) == 0:
187 return [el.split() for el in self]
188
189 res = SList()
190 for el in [f.split() for f in self]:
191 lineparts = []
192
193 for fd in fields:
194 try:
195 lineparts.append(el[fd])
196 except IndexError:
197 pass
198 if lineparts:
199 res.append(" ".join(lineparts))
200
201 return res
202
203 def sort(self,field= None, nums = False):
204 """ sort by specified fields (see fields())

Callers 2

test_SListFunction · 0.95
sortMethod · 0.80

Calls 1

SListClass · 0.85

Tested by 1

test_SListFunction · 0.76