pydicom.charset.decode_string

pydicom.charset.decode_string(value, encodings, delimiters)

Decode an encoded byte value into a unicode string using encodings.

New in version 1.2.

Parameters:
  • value (bytes or str) – The encoded byte string in the DICOM element value. Should be bytes for Python 3 and str for Python 2.
  • encodings (list of str) – The encodings needed to decode the string as a list of Python encodings, converted from the encodings in (0008,0005) Specific Character Set.
  • delimiters (set of int (Python 3) or characters (Python 2)) – A set of characters or character codes, each of which resets the encoding in value.
Returns:

The decoded unicode string. If the value could not be decoded, and enforce_valid_values is False, a warning is issued, and value is decoded using the first encoding with replacement characters, resulting in data loss. Returns str for Python 3 and unicode for Python 2.

Return type:

str or unicode

Raises:

UnicodeDecodeError – If enforce_valid_values is True and value could not be decoded with the given encodings.