Home > Blockchain >  IndexError: list index out of range, problems with selecting the elements of a list
IndexError: list index out of range, problems with selecting the elements of a list

Time:03-21

I am working on a project for my thesis and in one of my script i am subscribing a ROS message that was created by me. One of the parameters in this message is a list with target information.

targets [x_min: 447
y_min: 821
x_max: 460
y_max: 846
confianca: 0.99702954, x_min: 403
y_min: 839
x_max: 417
y_max: 869
confianca: 0.99742514]

This information is organized through other message.

In the script that i am trying to subscribe this message i was using the following line: variable_name.targets[0] to access to the information of the first target in the list, but when i run the script it gives me this error: IndexError: list index out of range

Anyone knows how to solve it?

CodePudding user response:

script :

lista = []

print(lista[0])

output:

line 3 , in <script.py>
print(lista[0])

IndexError: list index out of range

Maybe your list is empty ?

CodePudding user response:

You seem to have used the syntax for a dictionary instead of a list, I might be wrong here, but that seems like the issue to me. Maybe using a dictionary will help?

targets = {x_min: 447
y_min: 821
x_max: 460
y_max: 846
confianca: 0.99702954, x_min: 403
y_min: 839
x_max: 417
y_max: 869
confianca: 0.99742514}
  • Related