all Python 3codecsterm
codecs.BOM_UTF16_BE
byte order marks (BOM)
The bytes b'\xfe\xff', the UTF-16 big-endian byte order mark. The same object is available as codecs.BOM_BE.
Syntax
codecs.BOM_UTF16_BE # b'\xfe\xff'
It is rarer than LE because x86 and ARM are little-endian, but network formats and Java sometimes write UTF-16 BE. The 'utf-16' decoder picks the order from this BOM and strips it, while 'utf-16-be' leaves it in the text as the character '\ufeff'. codecs.BOM_BE and the legacy BOM32_BE are other names for this object.
Examples
import codecs
data = codecs.BOM_UTF16_BE + 'hi'.encode('utf-16-be')
print(data.decode('utf-16')) # → hi
print(repr(data.decode('utf-16-be'))) # → '\ufeffhi'
print(codecs.BOM_BE is codecs.BOM_UTF16_BE) # → True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy