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

Class SList

IPython/utils/text.py:87–230  ·  view source on GitHub ↗

List derivative with a special access attributes. These are normal lists, but with the special attributes: * .l (or .list) : value as list (the list itself). * .n (or .nlstr): value as a string, joined on newlines. * .s (or .spstr): value as a string, joined on spaces. * .p (or

Source from the content-addressed store, hash-verified

85
86
87class SList(list):
88 """List derivative with a special access attributes.
89
90 These are normal lists, but with the special attributes:
91
92 * .l (or .list) : value as list (the list itself).
93 * .n (or .nlstr): value as a string, joined on newlines.
94 * .s (or .spstr): value as a string, joined on spaces.
95 * .p (or .paths): list of path objects (requires path.py package)
96
97 Any values which require transformations are computed only once and
98 cached."""
99
100 def get_list(self):
101 return self
102
103 l = list = property(get_list)
104
105 def get_spstr(self):
106 try:
107 return self.__spstr
108 except AttributeError:
109 self.__spstr = ' '.join(self)
110 return self.__spstr
111
112 s = spstr = property(get_spstr)
113
114 def get_nlstr(self):
115 try:
116 return self.__nlstr
117 except AttributeError:
118 self.__nlstr = '\n'.join(self)
119 return self.__nlstr
120
121 n = nlstr = property(get_nlstr)
122
123 def get_paths(self):
124 try:
125 return self.__paths
126 except AttributeError:
127 self.__paths = [Path(p) for p in self if os.path.exists(p)]
128 return self.__paths
129
130 p = paths = property(get_paths)
131
132 def grep(self, pattern, prune = False, field = None):
133 """ Return all strings matching 'pattern' (a regex or callable)
134
135 This is case-insensitive. If prune is true, return all items
136 NOT matching the pattern.
137
138 If field is specified, the match must occur in the specified
139 whitespace-separated field.
140
141 Examples::
142
143 a.grep( lambda x: x.startswith('C') )
144 a.grep('Cha.*log', prune=1)

Callers 5

store_or_executeMethod · 0.90
getoutputMethod · 0.90
grepMethod · 0.85
fieldsMethod · 0.85
sortMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected