What is binascii.a2b_qp in Python?
The binascii is a widely used Python library for ASCII-encoded binary representations. It contains several methods for converting to binary from ASCII or hex, and vice versa.
binascii.a2b_qp is one of the methods of the Python binascii library. We can use this method to convert any data (string) to a binary format. This binary data is returned as a result.
Syntax
a2b_qp(data, header: bool=False)
binascii.a2b_qp takes an optional parameter of header as well. Setting it to true will allow underscores (_) in the input data to be treated as spaces. For example, hi_hel_p should return hi hel p with the spaces.
Code
Below are a few examples to illustrate the use of binascii.a2b_qp:
import binascii# Convert string into binary# In the AScii table, there is no character for 1F,# therefore, it is written as \x1fprint(binascii.a2b_qp("=1F_Hello _World", False))# In the AScii table, there is a character '?' for 3F,# therefore, it is replaced by ?print(binascii.a2b_qp("=3F_Hello _World", False))# Convert string into binary# Convert string into binary, header is set to true# this means underscore will be treated as a space.print(binascii.a2b_qp("=3F_Hello _World", True))
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved