【问题标题】:PYTHON: Index out of range in get item [closed]PYTHON:获取项目中的索引超出范围[关闭]
【发布时间】:2016-07-06 15:49:35
【问题描述】:

我在 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

【问题讨论】:

  • 您需要显示代码的相关部分

标签: python indexing range


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-27
    • 2017-10-02
    • 2014-11-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多