You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I reading an .xlsb file. I found some files which doesn't seem to open while other work.
Where the files which not worked throw this error - IndexError: list index out of range
from pyxlsb2 import open_workbook
xlsb_file_path= "sample_file.xlsb"
with open_workbook(xlsb_file_path) as wb:
for sheet in wb.sheets:
print(sheet.name)
Error -
This is what chatgpt is suggesting -
The error you're encountering is an IndexError with the message "list index out of range." This typically occurs when you're trying to access an element in a list using an index that is outside the valid range of indices for that list. In this specific case, the error is happening in the pyxlsb2 library code while parsing the formula of a cell.
The relevant part of the traceback is:
plaintext
Copy code
File "/home/ujwala/.venvs/ingest_venv/lib/python3.9/site-packages/pyxlsb2/formula.py", line 16, in stringify
return '' if not tokens else tokens.pop().stringify(tokens, workbook)
IndexError: list index out of range
Here's what's happening:
The tokens list is being accessed with tokens.pop().
The pop() method removes and returns the last item from the list.
The stringify method is then called on the popped item.
However, it seems that the tokens list is empty when pop() is called, resulting in an IndexError. The IndexError occurs because there is no item to pop from an empty list.
To fix this issue:
Check if tokens is not empty before calling pop().
Update the return statement in the stringify method of the pyxlsb2/formula.py file to include a check for an empty list:
return '' if not tokens else tokens.pop().stringify(tokens, workbook)
becomes:
return '' if not tokens else tokens.pop().stringify(tokens, workbook) if tokens else ''
This modification ensures that pop() is only called when tokens is not empty.
Update pyxlsb2 library to the latest version.
Ensure that you are using the latest version of the pyxlsb2 library, as this issue may have been addressed in a newer release. You can check the library's official repository for updates.
After making these changes, try running your code again and see if the issue persists. If the problem persists or if there's a specific version of pyxlsb2 that you're using, you might want to check the library's GitHub repository for open issues or consider reporting this issue to the library maintainers.
The text was updated successfully, but these errors were encountered:
Hello,
I reading an .xlsb file. I found some files which doesn't seem to open while other work.
Where the files which not worked throw this error -
IndexError: list index out of range
Error -

This is what chatgpt is suggesting -
The error you're encountering is an IndexError with the message "list index out of range." This typically occurs when you're trying to access an element in a list using an index that is outside the valid range of indices for that list. In this specific case, the error is happening in the pyxlsb2 library code while parsing the formula of a cell.
The relevant part of the traceback is:
plaintext
Copy code
IndexError: list index out of range
Here's what's happening:
The tokens list is being accessed with tokens.pop().
The pop() method removes and returns the last item from the list.
The stringify method is then called on the popped item.
However, it seems that the tokens list is empty when pop() is called, resulting in an IndexError. The IndexError occurs because there is no item to pop from an empty list.
To fix this issue:
Check if tokens is not empty before calling pop().
Update the return statement in the stringify method of the pyxlsb2/formula.py file to include a check for an empty list:
return '' if not tokens else tokens.pop().stringify(tokens, workbook)
becomes:
return '' if not tokens else tokens.pop().stringify(tokens, workbook) if tokens else ''
This modification ensures that pop() is only called when tokens is not empty.
Update pyxlsb2 library to the latest version.
Ensure that you are using the latest version of the pyxlsb2 library, as this issue may have been addressed in a newer release. You can check the library's official repository for updates.
After making these changes, try running your code again and see if the issue persists. If the problem persists or if there's a specific version of pyxlsb2 that you're using, you might want to check the library's GitHub repository for open issues or consider reporting this issue to the library maintainers.
The text was updated successfully, but these errors were encountered: