Source code for tesfdmtools.utils.cu
#!/usr/bin/env python3
'''
.. module:: cu
:synopsis: convert a byte type string into an ordinary ASCII string
.. moduleauthor:: Cor de Vries <c.p.de.vries@sron.nl>
'''
[docs]def cu(var):
'''
python3 keeps byte strings as type 'byte' (in python2 these strings
were automatically converted into ASCII strings).
- In the HDF5 files, the string attributes are all of type 'byte'
In order to process these strings, they should be converted to ASCII
using the decode('UTF-8')
Args:
* `var` = any variable
Returns:
* converted variable, if variable was of type 'bytes', otherwise return variable
'''
if type(var) is bytes:
return var.decode('UTF-8')
return var