Python .b2a_qp()
Anonymous contributor
Published Oct 24, 2025
Contribute to Docs
The .b2a_qp() function encodes binary data using the quoted-printable transfer encoding and returns a bytes object containing only ASCII characters.
Syntax
binascii.b2a_qp(data, quotetabs=false, istext=false, header=false)
Parameters:
data: The binary data to encode. Must be abytesorbytearrayobject.quotetabs(optional, default =False): WhenTrue, spaces and tabs are always encoded. By default, they’re encoded only when necessary according to the quoted-printable rules.istext(optional, default =False): WhenTrue, the input is treated as text and line endings are converted to\r\n. WhenFalse, line endings are not altered.header(optional, default =False): WhenTrue, spaces are encoded as underscores, making the output suitable for email headers (RFC 2047 format).
Return value:
Returns a bytes object containing the quoted-printable encoded ASCII representation of the input data.
Example
This example demonstrates encoding binary data containing special characters into quoted-printable ASCII:
import binascii# Binary data that includes an equals sign which must be quotedbinary_data = b"Codecademy = Awesome!\n"# Encode the binary data to Quoted-Printable ASCIIencoded = binascii.b2a_qp(binary_data)print(encoded)
This produces output similar to:
b'Codecademy =3D Awesome!=0A'
Note: To decode quoted-printable data back to binary, use
binascii.a2b_qp(data).
Codebyte Example
This example illustrates how .b2a_qp() encodes multiple special characters, tabs, and spaces in a bytes object:
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
- With Certificate
- Beginner Friendly.24 hours