I want to create an xls file, install xlrd and xlwt

Writing:

#!/usr/bin/python import xlwt workbook = xlwt.Workbook() workbook.save('my_file.xls') 

getting an error

 Traceback (most recent call last): File "./test2.py", line 4, in <module> workbook.save('my_file.xls') File "/usr/local/lib/python2.7/dist-packages/xlwt/Workbook.py", line 710, in save doc.save(filename_or_stream, self.get_biff_data()) File "/usr/local/lib/python2.7/dist-packages/xlwt/Workbook.py", line 680, in get_biff_data self.__worksheets[self.__active_sheet].selected = True IndexError: list index out of range 

did not quite understand the error, because for the python today I sat down for the first time

    1 answer 1

    You need to create at least one tab in the book:

     #!/usr/bin/python import xlwt workbook = xlwt.Workbook() workbook.add_sheet('my_sheet') workbook.save('my_file.xls')