Skip to content

Instantly share code, notes, and snippets.

@petrblahos
Created March 29, 2014 18:46
Show Gist options
  • Save petrblahos/9860571 to your computer and use it in GitHub Desktop.
Save petrblahos/9860571 to your computer and use it in GitHub Desktop.
Textual table
def make_text_table(row_count, column_width):
"""
Makes a textual table with the numbered rows and 2 columns. The first
column is 5 characters wide, the 2nd and 3rd columns are column_width
characters wide.
Params:
row_count The number of rows. The rows are then numbered
1 to row_count
column_width The width of the second and third column.
"""
column = ""
for i in range(column_width):
column += "-"
separator = "+-----+" + column + "+" + column + "+"
print separator
column_fmt = "% " + str(column_width) + "s"
fmt = "|% 5d|" + column_fmt + "|" + column_fmt + "|"
for i in range(row_count):
print fmt % (i + 1, " ", " ")
print separator
make_text_table(3, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment