Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexError: list index out of range #18

Open
Kuramdasu-ujwala-devi opened this issue Nov 29, 2023 · 0 comments
Open

IndexError: list index out of range #18

Kuramdasu-ujwala-devi opened this issue Nov 29, 2023 · 0 comments

Comments

@Kuramdasu-ujwala-devi
Copy link

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 -
image

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant