List index out of range hatası

Arkadaşlar nesne tanıma üzerine bir şeyler yapıyorum. Ve şöyle bir hata alıyorum. İndexler indexlerdeki eşleşmeler doğru fakat yinede çözülmüyor.

kod şu:

We’re going to convert the class index on the .txt files. As we’re working with only one class, it’s supposed to be class 0.

If the index is different from 0 then we’re going to change it.

import glob

import os

import re

txt_file_paths = glob.glob(r"data/obj/*.txt")

for i, file_path in enumerate(txt_file_paths):

# get image size

with open(file_path, "r") as f_o:

    lines = f_o.readlines()

    text_converted = []

    for line in lines:

        print(line)

        numbers = re.findall("[0-9.]+", line)

        print(numbers)

        if numbers:

          # Define coordinates

          text = "{} {} {} {} {}".format(0, numbers[1], numbers[2], numbers[3], numbers[4])

          text_converted.append(text)

          print(i, file_path)

          print(text)

    # Write file

    with open(file_path, 'w') as fp:

        for item in text_converted:

            fp.writelines("%s\n" % item)

hata şu:
IndexError Traceback (most recent call last)
in
19
20 # Define coordinates
—> 21 text = “{} {} {} {} {}”.format(0, numbers[1], numbers[2], numbers[3], numbers[4])
22 text_converted.append(text)
23 print(i, file_path)

IndexError: list index out of range

Soru sorarken sikca dusulen hatalar #1

1 Beğeni