I am trying to use the netCDF4 package with python. I want to do something which I think should be straightforward, but I can't make it work and I can't find any documentation on it. I have a list, and I simply want to store the list in a netCDF4.Variable object. I thought this code would store "newlist" in the netCDF4.Variable object "x_data", which is a component of the Dataset object "netdata":
netdata.variables['x_data'][:]=numpy.array(newlist)
But it's no go. I get the error message:
ValueError: setting an array element with a sequence.
BTW, I have imported both netCDF4 and numpy. Also BTW, this is the same error I get if I do this without converting newlist to a numpy array.
Surely there's a way to do this. Anyone know how? Thanks.
Addendum: This simple change gets me past the error message:
netdata.variables['x_data']=newlist
But I'm still not out of the woods. The data definitely gets stored in netdata.variables['x_data'], but then I close netdata and exit python, and examine the netCDF output, and the data just isn't there. Any ideas? Thanks again.