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

Method __str__

example_code/item_075.py:143–161  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

141 self.columns.append(data)
142
143 def __str__(self):
144 row_count = 1
145 for data in self.columns:
146 row_count = max(row_count, len(data.splitlines()) + 1)
147
148 rows = [""] * row_count
149 for j in range(row_count):
150 for i, data in enumerate(self.columns):
151 line = data.splitlines()[max(0, j - 1)]
152 if j == 0:
153 padding = " " * (len(line) // 2)
154 rows[j] += padding + str(i) + padding
155 else:
156 rows[j] += line
157
158 if (i + 1) < len(self.columns):
159 rows[j] += " | "
160
161 return "\n".join(rows)
162
163
164logging.getLogger().setLevel(logging.ERROR)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected