在Python中按名称检索netCDF全局属性的值

问题描述 投票:0回答:1

如何从Python中的netCDF文件中按名称检索全局属性的值?

我尝试过:

value = ncfile.getncattr(ncfile, global_attribute_name)

但出现错误:

NameError: name 'global_attribute_name' is not defined

我还阅读了netCDF4 API documentation的有关全局属性的部分,但我确定语法中有些地方我不理解。

有人可以帮忙吗?我是R用户,请移至Python,请保持谦虚。

python global-variables netcdf
1个回答
0
投票

global_attribute_name是参数。您应将其替换为要检索的属性名称,并用引号引起来。因此,假设属性名称为my_attr,然后使用

value = ncfile.getncattr(ncfile, 'my_attr')
© www.soinside.com 2019 - 2024. All rights reserved.