如何从Python中的netCDF文件中按名称检索全局属性的值?
我尝试过:
value = ncfile.getncattr(ncfile, global_attribute_name)
但出现错误:
NameError: name 'global_attribute_name' is not defined
我还阅读了netCDF4 API documentation的有关全局属性的部分,但我确定语法中有些地方我不理解。
有人可以帮忙吗?我是R用户,请移至Python,请保持谦虚。
global_attribute_name
是参数。您应将其替换为要检索的属性名称,并用引号引起来。因此,假设属性名称为my_attr
,然后使用
value = ncfile.getncattr(ncfile, 'my_attr')