【发布时间】:2019-12-01 18:42:39
【问题描述】:
我对 Python 很陌生。我必须写一个for循环。例如,有 2 个文件,比如说“文件”。我需要从每个中提取数据。我的代码如下,但是,它一直给我错误:
列表分配索引超出范围。
我已经搜索了现有的答案,但很抱歉我不明白如何申请我的案例。非常感谢。
import xarray as xr
ds = []
for i in range(0,2):
ds[i] = xr.open_dataset(files[i])
【问题讨论】:
-
这能回答你的问题吗? python : list index out of range error
-
只要
for file in files: ds.append(xr.open_dataset(file)),你根本不需要使用索引。
标签: python-3.x