MCPcopy Create free account
hub / github.com/ActiveState/code / prettyPrint

Function prettyPrint

recipes/Python/137951_Dump_all_attributes/recipe-137951.py:178–196  ·  view source on GitHub ↗

Pretty prints the given string to break at an occurrence of split where necessary to avoid lines longer than maxlen. This will overflow the line if no convenient occurrence of split is found

(string, maxlen=75, split=' ')

Source from the content-addressed store, hash-verified

176 return '\n'.join(map(formatline, *cols))
177
178def prettyPrint(string, maxlen=75, split=' '):
179 """Pretty prints the given string to break at an occurrence of
180 split where necessary to avoid lines longer than maxlen.
181
182 This will overflow the line if no convenient occurrence of split
183 is found"""
184
185 # Tack on the splitting character to guarantee a final match
186 string += split
187
188 lines = []
189 oldeol = 0
190 eol = 0
191 while not (eol == -1 or eol == len(string)-1):
192 eol = string.rfind(split, oldeol, oldeol+maxlen+len(split))
193 lines.append(string[oldeol:eol])
194 oldeol = eol + len(split)
195
196 return lines
197
198def nukenewlines(string):
199 """Strip newlines and any trailing/following whitespace; rejoin

Callers 2

dumpObjFunction · 0.85
prettyPrintColsFunction · 0.85

Calls 2

rfindMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected