<p>我可能只是个白痴,但我基本上只是试图从txt文件中读取数据。当我试图访问数据列表时,我得到“列表索引超出范围”。当我运行它时,它实际上会打印数据的值,但例如,我不能将它们附加到新列表中</p>
<pre><code>with open('dust_extinction_test_data.txt', 'r') as f:
for line in f.readlines()[1:]:
data = line.split()
print(data[0])
</code></pre>
<p><a href="https://i.stack.imgur.com/I6Sdg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/I6Sdg.png" alt="This is the data format in a txt file in case that's helpful"/></a></p>
<p>这是控制台上的结果,我的意思是,数据[0]值仍然打印,但我仍然得到一个错误
<a href="https://i.stack.imgur.com/sEInN.png" rel="nofollow noreferrer">Console output</a></p>