1

I want to read data from an .ods file (using ezodf), and convert it to JSON.

Here is my code:

try:
    while conf[i, 2].value != None:
        export_data['priorities'][conf[i, 2].value] = str(int(conf[i, 3].value))
        i+=1
except IndexError:
    print("This probably has a better solution.");

conf[x, y] references a cell in the conf sheet. As you can see I want to read the values of column i as long as there isn't empty cell in it.

The problem is that the first empty cell is raising an IndexError exception.

Can I fix this in a simple way, for example, check the length of this column?

1 Answer 1

1

This should be what you're looking for (I'm assuming conf is a spreadsheet table):

for i in range(conf.nrows()):
   export_data['priorities'][conf[i, 2].value] = str(int(conf[i, 3].value))

But you should know that the int(conf[i, 3].value) bit will throw an exception if the spreadsheet contains a non-integral value.

There's nothing terribly wrong with your try/except method of doing this.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.