MCPcopy Create free account
hub / github.com/bslatkin/effectivepython / ColumnPrinter

Class ColumnPrinter

example_code/item_073.py:205–230  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

203 return state
204
205class ColumnPrinter:
206 def __init__(self):
207 self.columns = []
208
209 def append(self, data):
210 self.columns.append(data)
211
212 def __str__(self):
213 row_count = 1
214 for data in self.columns:
215 row_count = max(row_count, len(data.splitlines()) + 1)
216
217 rows = [""] * row_count
218 for j in range(row_count):
219 for i, data in enumerate(self.columns):
220 line = data.splitlines()[max(0, j - 1)]
221 if j == 0:
222 padding = " " * (len(line) // 2)
223 rows[j] += padding + str(i) + padding
224 else:
225 rows[j] += line
226
227 if (i + 1) < len(self.columns):
228 rows[j] += " | "
229
230 return "\n".join(rows)
231
232
233grid = Grid(5, 9)

Callers 1

item_073.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected