PYTHON:get item中的索引超出范围

2024-10-03 13:18:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我在python中遇到了这个错误,我不知道索引在下面指定的第756行中的位置:

Traceback (most recent call last):
  File "EMMMOIScenario.py", line 22, in <module>
    TheEMMSim.DVThrusterDynObject.ThrusterData[i].MaxThrust=0 #sets the ith thruster (in the square bracket) to zero
  File "/Users/emanalawadhi/Desktop/MBRSCWork/TASKSWork/SSDD/EMX/ADCS/Simulator/EMMArchive/EMMData/EMMModules/../../Basilisk/modules/thruster_dynamics.py", line 756, in __getitem__
    return _thruster_dynamics.ThrusterConfigVector___getitem__(self, *args)
IndexError: index out of range

Tags: theinpymost错误linecallfile
1条回答
网友
1楼 · 发布于 2024-10-03 13:18:28

IndexError意味着您可能试图访问不存在的列表中的项。 它看起来像是一个列表,而i是你想要的元素的索引。如果stresserData中有3个项(例如:ThrusterData = ['string 1', 'string 2', string 3'])并运行ThrusterData[0],那么您将得到'string 1',但是{}将导致索引错误,因为列表是0索引的,并且没有stresserdata[3]

相关问题 更多 >