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

Method __str__

example_code/item_072.py:165–183  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected