[Tutor] printing columns
alan.gauld@bt.com
alan.gauld@bt.com
Fri, 26 Jul 2002 14:21:27 +0100
> Hmmm... this is a little tricky, just because tab spacing can be
> potentially different on other systems; a potential solution
> should use spaces instead to guarantee that things look
> correct on all systems.
> def layoutColumns(columns1, columns2, spacing=8):
> width_of_first_column = max([len(c) + spacing for c in columns1])
> lines = []
> for col1, col2 in zip(columns1, columns2):
> lines.append(col1
> + " " * (width_of_first_column - len(col1))
> + col2)
> return lines
Or use format strings:
fmt = "#define %20s\t%3d"
Or similar...
Alan G.