Python Glossary Русский

all Python 3codecsterm

codecs.BOM_UTF32

byte order marks (BOM)

The UTF-32 BOM in the machine's native byte order: BOM_UTF32_LE on x86 and ARM. The 'utf-32' codec writes it at the start of its output.

Syntax

codecs.BOM_UTF32  # b'\xff\xfe\x00\x00' на little-endian

Like BOM_UTF16, its value depends on the machine, so file sniffing compares against BOM_UTF32_LE and BOM_UTF32_BE explicitly. The 'utf-32' codec puts the mark into every encode call: two strings encoded separately and concatenated leave a second mark in the middle, which decodes as the character '\ufeff'.

Examples

import codecs
data = 'a'.encode('utf-32') + 'b'.encode('utf-32')
print(data.startswith(codecs.BOM_UTF32))  # → True
print(repr(data.decode('utf-32')))  # → 'a\ufeffb'

See also

Open in the full glossarydocs.python.orgReport an inaccuracy