This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Hi, The easiest way is to use the NumPy type corresponding to what you want, in this case numpy.int32: from netCDF4 import Dataset import numpy as np nc = Dataset('test3.nc', 'w') nc.myattr = np.int32(5) nc.close() nc = Dataset('test3.nc') print(type(nc.myattr)) # Prints "numpy.int32" Hope this helps, Ryan > Hello - > > Is it possible to write 32-bit integer attributes with the Python netCDF4 > module, rather than the default 64 bit integers? I’ve tried the obvious thing > of using {attribute_name:int(1)} in the all to ncsetattrs(). > Ticket Details =================== Ticket ID: QOU-764758 Department: Support Python Priority: Low Status: Closed =================== NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.