0

I m trying to write some data in an excel file.

rounds= [[(0, 2), (1, 3)], [(2, 0), (1, 3)], [(2, 1), (0, 3)], [(0, 3), (2, 1)], [(3, 0), (1, 2)], [(2, 0), (3, 1)]]

And I want to write them in a list as below: (round is the index of the sub-list they belong)

pl1 pl2 round
0 2 0
1 3 0
2 0 1
1 3 1
2 1 2
0 3 2

and so on.....

I'm trying to move the data to the excel file using xlxswrite, but I get this error

(Please, ignore that I don't put headers in excel columns, I know)

import xlsxwriter

workbook = xlsxwriter.Workbook("table.xls")
worksheet = workbook.add_worksheet()

rounds= [[(0, 2), (1, 3)], [(2, 0), (1, 3)], [(2, 1), (0, 3)], [(0, 3), (2, 1)], [(3, 0), (1, 2)], [(2, 0), (3, 1)]]

for index,entry in enumerate(rounds):
    for pairing in entry:
        worksheet.write(index,0,pairing(0))
        worksheet.write(index,0,pairing(1))
        worksheet.write(index,0,str(index))

But I get the error :

worksheet.write(index,0,pairing(0))
TypeError: 'tuple' object is not callable

How can I access the data of each tuple then?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
ToErotimatiko
  • 179
  • 2
  • 3
  • 14
  • 1
    You need square brackets like `pairing[0]`. Better yet, you can directly unpack the tuples: `for a, b in entry:` and then set the values like so: `worksheet.write(index, 0, a); worksheet.write(index, 0, b)`. – fsimonjetz Mar 05 '22 at 18:43
  • @fsimonjetz Oh, thank you , you are correct! I also have another question. It only writes the second tuple's data of each sub-list, why could that be ? – ToErotimatiko Mar 05 '22 at 19:37
  • I realize that I never "jump" to the next row, but how do I do it for the next "couple" ? – ToErotimatiko Mar 05 '22 at 19:54

0 Answers0