all Python 3until 3.11Removed from the standard libraryterm
binhex
removed modules
Module for encoding files in the BinHex4 format of classic Mac OS. Removed in Python 3.11; use base64 to encode bytes as text.
Syntax
import binhex # до 3.11
BinHex4 turned a classic Mac OS file into ASCII text so it could travel by mail. The format fell out of use long ago; the module was deprecated in Python 3.9 and removed in 3.11 along with binascii.a2b_hqx(), b2a_hqx(), rlecode_hqx() and rldecode_hqx(). How to rewrite: to send bytes as text use base64.b64encode() and base64.b64decode(); for a file, read it as bytes, encode it and write the result. The binascii.crc_hqx() checksum is still available.
Examples
# Python 3.11+
try:
import binhex
except ModuleNotFoundError as e:
print(type(e).__name__) # → ModuleNotFoundError
# Python 3.11+
import base64, binascii
text = base64.b64encode(b'hello')
print(text) # → b'aGVsbG8='
print(base64.b64decode(text)) # → b'hello'
print(binascii.crc_hqx(b'hello', 0)) # → 50018
import binhex
with open('in.txt', 'wb') as f:
f.write(b'hello')
binhex.binhex('in.txt', 'in.hqx')
binhex.hexbin('in.hqx', 'back.txt')
with open('back.txt', 'rb') as f:
print(f.read()) # → b'hello'
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy