Cloud Stack Ninja

I read one xlsx file in this i have two sheets and i want store in a dictionary of tuples but at the end of the tuples, I got extra comma.

my output:
data_dict = {"sheet1":[('A',), ('B',), ('C',), ('D',)],"sheet2":[('A',), ('B',), ('C',), ('D',)]}

The correct output I want:
data_dict = {"sheet1":[('A'), ('B'), ('C'), ('D')],"sheet2":[('A'), ('B'), ('C'), ('D')]}

My current code is

import openpyxl
wb = load_workbook(xlsx_filename)
data_dict = {}
for sheet in wb:

    data_dict[sheet.title] = []
    for row in sheet.rows:
        row_wise_data = tuple([cell.value for cell in row])
#print(data_dict)  # result in dictionary

return data_dict

Read more here:

Content Attribution

This content was originally published by abhi spdy at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: