Python Glossary Русский

all Python 3binasciifunction

binascii.b2a_qp()

uuencode and quoted-printable

Encodes bytes to quoted-printable: ASCII stays as is, everything else becomes =XX. The format of MIME email bodies and headers.

Syntax

binascii.b2a_qp(data, quotetabs=False, istext=True, header=False)

The '=' sign itself is escaped as '=3D', so 'x = 1' becomes 'x =3D 1', and that is not a bug. Cyrillic grows threefold: each UTF-8 byte becomes three characters. header=True encodes spaces as '_' for email headers (RFC 1522). For email in general the email package is handier, as it chooses between quoted-printable and base64 itself.

Examples

import binascii
print(binascii.b2a_qp(b'x = 1'))  # → b'x =3D 1'
print(binascii.b2a_qp('Пр'.encode('utf-8')))  # → b'=D0=9F=D1=80'
print(binascii.b2a_qp(b'a b', header=True))  # → b'a_b'

See also

Open in the full glossarydocs.python.orgReport an inaccuracy