Python Glossary Русский

all Python 3binasciifunction

binascii.a2b_uu()

uuencode and quoted-printable

Decodes one uuencode line back to bytes. It takes the data length from the line's first character, not from the line's actual length.

Syntax

binascii.a2b_uu(string)

Lines go in one at a time: a whole uuencoded file with its 'begin 644 name' header does not decode in one call; drop the header and the 'end' line and call it per line. If the first character (the length) disagrees with the data, you get binascii.Error 'Trailing garbage'. The uu module was removed in 3.13, so binascii is the last tool for this format.

Examples

import binascii
line = binascii.b2a_uu(b'hello')
print(line[:1], len(line))  # → b'%' 10 — '%' кодирует длину 5
print(binascii.a2b_uu(line))  # → b'hello'
try:
    binascii.a2b_uu(b'"' + line[1:])
except binascii.Error as e:
    print(e)  # → Trailing garbage — заголовок обещал 2 байта, а данных больше

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy