Python代码:
from netCDF4 import Dataset
# 打开.nc文件
file_path = '2023.nc'
data = Dataset(file_path, 'r')
# 打印变量名称及其对应的尺寸
print("文件中的变量及其尺寸:")
for name, variable in data.variables.items():
print(f"变量名: {name}, 尺寸: {variable.shape}, 数据类型: {variable.dtype}")
# 关闭文件
data.close()
打印输出nc文件信息(包含变量名、尺寸、数据类型):