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

Class ColumnPrinter

example_code/item_072.py:158–183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

156
157print("Example 3")
158class ColumnPrinter:
159 def __init__(self):
160 self.columns = []
161
162 def append(self, data):
163 self.columns.append(data)
164
165 def __str__(self):
166 row_count = 1
167 for data in self.columns:
168 row_count = max(row_count, len(data.splitlines()) + 1)
169
170 rows = [""] * row_count
171 for j in range(row_count):
172 for i, data in enumerate(self.columns):
173 line = data.splitlines()[max(0, j - 1)]
174 if j == 0:
175 padding = " " * (len(line) // 2)
176 rows[j] += padding + str(i) + padding
177 else:
178 rows[j] += line
179
180 if (i + 1) < len(self.columns):
181 rows[j] += " | "
182
183 return "\n".join(rows)
184
185
186grid = LockingGrid(5, 9) # Changed

Callers 1

item_072.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected