##// END OF EJS Templates
sort() returns SList (obviously), %cpaste foo assigns the pasted block to foo as string list
Ville M. Vainio -
Show More
@@ -3195,7 +3195,7 b' Defaulting color scheme to \'NoColor\'"""'
3195 3195 exec b in self.user_ns
3196 3196 self.user_ns['pasted_block'] = b
3197 3197 else:
3198 self.user_ns[par] = block
3198 self.user_ns[par] = SList(block.splitlines())
3199 3199 print "Block assigned to '%s'" % par
3200 3200
3201 3201 def magic_quickref(self,arg):
@@ -1137,7 +1137,7 b' class SList(list):'
1137 1137 res.append(" ".join(lineparts))
1138 1138
1139 1139 return res
1140 def sort(self,field, nums = False):
1140 def sort(self,field= None, nums = False):
1141 1141 """ sort by specified fields (see fields())
1142 1142
1143 1143 Example::
@@ -1148,7 +1148,10 b' class SList(list):'
1148 1148 """
1149 1149
1150 1150 #decorate, sort, undecorate
1151 dsu = [[SList([line]).fields(field), line] for line in self]
1151 if field is not None:
1152 dsu = [[SList([line]).fields(field), line] for line in self]
1153 else:
1154 dsu = [[line, line] for line in self]
1152 1155 if nums:
1153 1156 for i in range(len(dsu)):
1154 1157 numstr = "".join([ch for ch in dsu[i][0] if ch.isdigit()])
@@ -1161,11 +1164,15 b' class SList(list):'
1161 1164
1162 1165
1163 1166 dsu.sort()
1164 return [t[1] for t in dsu]
1167 return SList([t[1] for t in dsu])
1165 1168
1166 1169 def print_slist(arg):
1167 1170 """ Prettier (non-repr-like) and more informative printer for SList """
1168 print "SList (.p, .n, .l, .s, .grep(), .fields() available). Value:"
1171 print "SList (.p, .n, .l, .s, .grep(), .fields(), sort() available):"
1172 if hasattr(arg, 'hideonce') and arg.hideonce:
1173 arg.hideonce = False
1174 return
1175
1169 1176 nlprint(arg)
1170 1177
1171 1178 print_slist = result_display.when_type(SList)(print_slist)
@@ -32,6 +32,7 b' New features'
32 32 * sh profile: ./foo runs foo as system command, no need to do !./foo anymore
33 33 * String lists now support 'sort(field, nums = True)' method (to easily
34 34 sort system command output). Try it with 'a = !ls -l ; a.sort(1, nums=1)'
35 * '%cpaste foo' now assigns the pasted block as string list, instead of string
35 36
36 37
37 38
General Comments 0
You need to be logged in to leave comments. Login now