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

Method __str__

example_code/item_074.py:162–180  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected