MCPcopy Index your code
hub / github.com/clips/pattern / pprint

Function pprint

pattern/db/__init__.py:2182–2216  ·  view source on GitHub ↗

Prints a string where the rows in the datasheet are organized in outlined columns.

(datasheet, truncate=40, padding=" ", fill=".")

Source from the content-addressed store, hash-verified

2180_truncate = truncate
2181
2182def pprint(datasheet, truncate=40, padding=" ", fill="."):
2183 """ Prints a string where the rows in the datasheet are organized in outlined columns.
2184 """
2185 # Calculate the width of each column, based on the longest field in each column.
2186 # Long fields can be split across different lines, so we need to check each line.
2187 w = [0 for column in datasheet.columns]
2188 R = []
2189 for i, row in enumerate(datasheet.rows):
2190 fields = []
2191 for j, v in enumerate(row):
2192 # Cast each field in the row to a string.
2193 # Strings that span beyond the maximum column width are wrapped.
2194 # Thus, each "field" in the row is a list of lines.
2195 head, tail = _truncate(decode_utf8(v), truncate)
2196 lines = []
2197 lines.append(head)
2198 w[j] = max(w[j], len(head))
2199 while len(tail) > 0:
2200 head, tail = _truncate(tail, truncate)
2201 lines.append(head)
2202 w[j] = max(w[j], len(head))
2203 fields.append(lines)
2204 R.append(fields)
2205 for i, fields in enumerate(R):
2206 # Add empty lines to each field so they are of equal height.
2207 n = max([len(lines) for lines in fields])
2208 fields = [lines+[""] * (n-len(lines)) for lines in fields]
2209 # Print the row line per line, justifying the fields with spaces.
2210 for k in range(n):
2211 for j, lines in enumerate(fields):
2212 s = lines[k]
2213 s += ((k==0 or len(lines[k]) > 0) and fill or " ") * (w[j] - len(lines[k]))
2214 s += padding
2215 print s,
2216 print

Callers 3

08-web.pyFile · 0.90
02-datasheet.pyFile · 0.90
03-parse.pyFile · 0.50

Calls 3

decode_utf8Function · 0.85
lenFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…