[Numpy-discussion] Copy netcdf attributes between different files

Giovanni Plantageneto g.plantageneto@gmail....
Mon Nov 14 11:04:42 CST 2011


Hi everybody,
I am using netCDF4 library to read and write from netcdf files. I
would like to copy all the attributes of one file to another one, in a
way like this:

---

from netCDF4 import Dataset as ncdf

file1 = ncdf('file1.nc', mode='r', format='NETCDF4_CLASSIC')
...
file2 = ncdf('file1.nc', mode='w', format='NETCDF4_CLASSIC')
for att in file1.ncattrs():
   file2.att = file1.getncatt(att)
...
file1.close()
file2.close()

---

But this will not work as only one attribute named "att" in file2 will
be created. How should I do this?
Thanks.


More information about the NumPy-Discussion mailing list