Python Glossary Русский

all Python 3base64function

base64.decode()

legacy interface

Legacy interface: reads a file containing Base64 and writes the decoded bytes into another file.

Syntax

base64.decode(input, output)

Both files must be opened in binary mode; lines are read with readline, so multi-line MIME text is handled without preparation. Like b64decode without validate, foreign characters in the lines are silently skipped. It is the counterpart of base64.encode and reads its output without loss.

Examples

import base64
with open('data.b64', 'wb') as f:
    f.write(b'aGk/\nPg==\n')
with open('data.b64', 'rb') as src, open('data.bin', 'wb') as dst:
    base64.decode(src, dst)
with open('data.bin', 'rb') as f:
    print(f.read())  # → b'hi?>'

See also

Open in the full glossarydocs.python.orgReport an inaccuracy