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

Method __str__

example_code/item_071.py:205–223  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected