Created
February 18, 2016 00:11
-
-
Save omad/936cea57873a29c34de8 to your computer and use it in GitHub Desktop.
NetCDF4 Python String Attribute Experiments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import netCDF4 | |
import sys | |
filename = sys.argv[1] | |
unicode_string = u"\N{GREEK CAPITAL LETTER DELTA}" | |
normal_string = "bob" | |
nc = netCDF4.Dataset(filename, 'w') | |
nc.uni = unicode_string | |
nc.encoded_uni = unicode_string.encode('utf8') | |
nc.normal_string = normal_string | |
nc.encoded_normal_string = normal_string.encode('utf8') | |
nc.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python2 netcdfstringstest.py py2test.nc | |
$ python3 netcdfstringstest.py py3test.nc | |
$ ncdump py2test.nc | |
netcdf py2test { | |
// global attributes: | |
string :uni = "Δ" ; | |
:encoded_uni = "Δ" ; | |
:normal_string = "bob" ; | |
:encoded_normal_string = "bob" ; | |
} | |
$ ncdump py3test.nc | |
netcdf py3test { | |
// global attributes: | |
string :uni = "Δ" ; | |
:encoded_uni = "Δ" ; | |
string :normal_string = "bob" ; | |
:encoded_normal_string = "bob" ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment