pydicom.charset.encode_string¶
-
pydicom.charset.encode_string(value, encodings)¶ Encode a unicode string value into
bytesusing encodings.New in version 1.2.
- Parameters
value (str or unicode) – The unicode string as presented to the user. Should be
strfor Python 3 andunicodefor Python 2.encodings (list of str) – The encodings needed to encode the string as a list of Python encodings, converted from the encodings in (0008,0005) Specific Character Set.
- Returns
The encoded string. If value could not be encoded with any of the given encodings, and
enforce_valid_valuesisFalse, a warning is issued, and value is encoded using the first encoding with replacement characters, resulting in data loss. Should bebytesfor Python 3 andstrfor Python 2.- Return type
bytes or str
- Raises
UnicodeEncodeError – If
enforce_valid_valuesisTrueand value could not be encoded with the supplied encodings.