##// END OF EJS Templates
SList.grep()
vivainio -
Show More
@@ -5,7 +5,7 b' General purpose utilities.'
5 5 This is a grab-bag of stuff I find useful in most programs I write. Some of
6 6 these things are also convenient when working at the command line.
7 7
8 $Id: genutils.py 2661 2007-08-22 20:43:34Z vivainio $"""
8 $Id: genutils.py 2726 2007-09-07 15:07:17Z vivainio $"""
9 9
10 10 #*****************************************************************************
11 11 # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu>
@@ -1008,9 +1008,24 b' class SList(list):'
1008 1008
1009 1009 p = paths = property(get_paths)
1010 1010
1011 def grep(self, pattern, prune = False):
1012 """ Return all strings matching 'pattern' (a regex or callable)
1013
1014 This is case-insensitive. If prune is true, return all items
1015 NOT matching the pattern.
1016 """
1017 if isinstance(pattern, basestring):
1018 pred = lambda x : re.search(pattern, x, re.IGNORECASE)
1019 else:
1020 pred = pattern
1021 if not prune:
1022 return SList([el for el in self if pred(el)])
1023 else:
1024 return SList([el for el in self if not pred(el)])
1025
1011 1026 def print_slist(arg):
1012 1027 """ Prettier (non-repr-like) and more informative printer for SList """
1013 print "SList (.p, .n, .l, .s available). Value:"
1028 print "SList (.p, .n, .l, .s, .grep() available). Value:"
1014 1029 nlprint(arg)
1015 1030
1016 1031 print_slist = result_display.when_type(SList)(print_slist)
@@ -3,6 +3,8 b''
3 3 * iplib.py: do not auto-alias "dir", it screws up other dir auto
4 4 aliases.
5 5
6 * genutils.py: SList.grep() implemented.
7
6 8 2007-09-07 Fernando Perez <Fernando.Perez@colorado.edu>
7 9
8 10 * IPython/OInspect.py (Inspector.pinfo): fixed bug that was
General Comments 0
You need to be logged in to leave comments. Login now