I have a function which takes a nested list that I input and writes it into the console in the format that I am after.
def print_table(table):
longest_cols = [(max(
[len(str(row[i])) for row in table]) + 2)
for i in range(len(table[0]))]
row_format = "".join(["{:>" + str(longest_col) + "}"
for longest_col in longest_cols])
for row in table:
print(row_format.format(*row))
How would I modify the function so that it writes the output into an output file?
I attempted this by saying
x = print_table(table)
and then
f.write(x)
f.close()
But all this did is write none into the output file
Any help in this is greatly appreciated. Thank you!