У меня есть приложение Kivy, которое считает слова в файлах данных. Сначала я использую FileChooser для выбора файла (если файл не был выбран, все работает нормально):
FileChooserListView:
canvas.before:
Color:
rgb: .4, .5, .5
on_selection: root.select(*args)
, а затем нажимаю это:
и получите эту ошибку:
File "C:\GUI Projects\wordcount\wordcount.kv", line 53, in <module>
on_selection: root.select(*args)
File "wordcount.py", line 15, in select
filepath = args[1][0]
IndexError: list index out of range
Это означает, что этот блок, четвертая строка:
class DocxPptxWindow(Screen):
def select(self, *args):
filepath = args[1][0]
text = txt.process(filepath)
text = text.decode("utf8")
text = text.replace("\n", " ") #change tags to spaces
text = text.replace("\t", " ")
text = text.replace(" ", " ") #delete continous doublespaces
text = text.replace(" ", " ")
text = text.replace(" ", " ")
text = text.split() #convert string into list of words
word_list = [w for w in text if w.isalnum()] #deleting non-alnum
num_w = len(word_list)
try: self.label.text = str(num_w)
except: pass
Очевидно, мне нужно как-то его «закрыть», но Я не нашел его в Kivi Tutorial и заранее прошу прощения за недостаток опыта.
Или мне нужно определить, что условие "select" будет выполнено, аналогично это . Но это решение для IndexError: tuple index out of range
ошибки, а не IndexError: list index out of range
.
Любая помощь очень ценится.