Ask Anything Monday - Weekly Thread

Hi all,

I have some problem with my email message. I only want the table from my "Summary" sheet in this excel sheet. However the message sent out is like this ([['Brand Name', 'Sales'], ['a', 123.0], ['b', 24.0], ['c', 435.0], ['d', 345.0], ['e', 46.0], ['f', 67.0], ['g', 456.0], ['h', 567.0], ['i', 7434.0], ['j', 463.0]] ). I want to know how i can put it in a table form?

# Open spreadsheet
workbook = xlrd.open_workbook("Test.xlsx")

# Open a sheet by name
worksheet = workbook.sheet_by_name("Summary")

total_rows = worksheet.nrows
total_cols = worksheet.ncols

table = list()
record = list()

for x in range(total_rows):
    for y in range(total_cols):
        record.append(worksheet.cell(x, y).value)
    table.append(record)
    record = []
    x += 1

# Email message
msg.set_content('{0}'.format(table))

I tried using this code to make a table. However I dont know how to put it in the message.

for item in table:
    print(item[0], " "*(20-len(item[0])), item[1])

Thanks in advance!

/r/learnpython Thread