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?

4

1 に答える 1

1

これはあなたが探しているものでなければなりません(私はconfスプレッドシートテーブルであると仮定しています):

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

int(conf[i, 3].value)ただし、スプレッドシートに非整数値が含まれている場合、ビットは例外をスローすることを知っておく必要があります。

これを行うあなたのtry/except方法にひどく悪いことは何もありません。

于 2013-01-25T17:10:54.177 に答える