Python Glossary Русский

all Python 3until 3.13Removed from the standard libraryterm

uu

removed modules

Encode binary data as text in the uuencode format. Removed in Python 3.13 — use base64.

Syntax

import uu  # до 3.13

uu.encode(infile, outfile) turned a binary file into text with 'begin 644 name' … 'end' lines, and uu.decode() turned it back — this is how attachments travelled by mail and Usenet before MIME. PEP 594 dropped it: uuencode was long ago replaced by Base64. How to port: for new data use base64.b64encode() and base64.b64decode(). If you must read or produce the uu format itself, codecs.encode(data, 'uu') and codecs.decode(text, 'uu') do it without the module, and binascii.b2a_uu() and a2b_uu() encode one line at a time. The standard-uu package on PyPI restores the module.

Examples

# Python 3.13+
try:
    import uu
except ModuleNotFoundError as e:
    print(type(e).__name__)  # → ModuleNotFoundError
# Python 3.13+
import base64, codecs
print(base64.b64encode(b'Hi!'))  # → b'SGkh'
packed = codecs.encode(b'Hi!', 'uu')
print(codecs.decode(packed, 'uu'))  # → b'Hi!'
import io, uu
out = io.BytesIO()
uu.encode(io.BytesIO(b'Hi!'), out, name='hi.txt')
print(out.getvalue().splitlines()[0])  # → b'begin 666 hi.txt'
back = io.BytesIO()
uu.decode(io.BytesIO(out.getvalue()), back)
print(back.getvalue())  # → b'Hi!'

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy