Python Glossary Русский

all Python 3Exceptionsexception

BytesWarning

built-in exceptions

A warning about dubious bytes/bytearray operations.

Syntax

raise BytesWarning

By default it stays silent: comparing bytes with str simply evaluates to False, and str(b'abc') quietly yields text with a stray b in it — nothing stops you. The warning is emitted only when the interpreter runs with -b, and -bb turns it into a hard error; that flag pair is how you hunt down places where bytes and text got mixed up.

Examples

try:
    raise BytesWarning
except BytesWarning as e:
    print(type(e).__name__)   # → BytesWarning

See also

Open in the full glossarydocs.python.orgReport an inaccuracy