bytes object
A Python value holding raw bytes, numbers from 0 to 255, written like b"abc", as opposed to a string of characters.
In more detail
Call encode on a string to get bytes and decode on bytes to get a string back, for example text.encode("utf-8") and data.decode("utf-8"). Files opened in binary mode, such as "rb", read and write bytes, and network and storage libraries work with bytes too, so text must be encoded first.
Examples
b'payload'Kafka keys, values and header values are bytes.'value'.encode()"café".encode("utf-8")Related terms
- string — A sequence of characters, that is, a piece of text.
- character encoding — The rule for turning text characters into bytes and back, such as UTF-8.
- record value — The main content of a record, stored by Kafka as raw bytes it never inspects.
- file mode — The second argument to open(), which says how the file will be used: "r" read, "w" write from scratch, "a" append, with "b" added for bytes.
Taught in
- Acknowledgements: What Acks Means For Durability — Apache Kafka & Event Streaming
- A Consumer In Python — Apache Kafka & Event Streaming
- Headers, Envelopes And Event Metadata — Apache Kafka & Event Streaming
- What Python Is, And Where It Came From — Hands-on Python: Complete Video Course & Book
- Paths And Files The Modern Way — Hands-on Python: Complete Video Course & Book