binary mode

Opening a file with b in its mode, so reads return bytes exactly as stored.

In more detail

In binary mode nothing is decoded or converted: read() returns a bytes object and write() requires bytes. A binary handle can also fill an existing bytearray with readinto(). Use it for images, archives and any data that is not text.

Example

with open('data.bin', 'rb') as f:
    raw = f.read()   # bytes

Related terms

Taught in

References

Certification courses