sidpy.base.string_utils.clean_string_att

sidpy.base.string_utils.clean_string_att(att_val)[source]

Replaces any unicode objects within lists with their string counterparts to ensure compatibility with python 3. If the attribute is indeed a list of unicodes, the changes will be made in-place

Parameters:

att_val (object) – Attribute object

Returns:

att_val – Attribute object

Return type:

object

Notes

The h5py package used for reading and manipulating HDF5 files has issues which necessitate the encoding of attributes whose values are lists of strings. This method encodes lists of strings correctly so that they can directly be written to HDF5 without causing any errors. All other kinds of simple attributes - single strings, numbers, lists of numbers are unmodified by this function.

Examples

>>> import sidpy
>>> expected = ['a', 'bc', 'def']
>>> returned = sidpy.string_utils.clean_string_att(expected)
>>> print('List of strings value: {} encoded to: {}'.format(expected, returned))
>>>
>>> expected = [1, 2, 3.456]
>>> returned = sidpy.string_utils.clean_string_att(expected)
>>> print('List of numbers value: {} returned as is: {}'.format(expected, returned))