Created
March 29, 2014 18:46
-
-
Save petrblahos/9860571 to your computer and use it in GitHub Desktop.
Textual table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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