from io import BytesIO b = BytesIO(b'ab') b.write(b'cd') b.seek(0) assert b'abcd' == b.read() # Fails because b.read() returns b'cd'