Skip to content

Instantly share code, notes, and snippets.

@markrwilliams
Last active August 29, 2015 14:01
Show Gist options
  • Save markrwilliams/34b32ba8e8bb6bacf080 to your computer and use it in GitHub Desktop.
Save markrwilliams/34b32ba8e8bb6bacf080 to your computer and use it in GitHub Desktop.
import os
import io
FN = 'thefile'
with open(FN, 'w') as f:
f.write(b'abcdefgh\n'
b'ijlkmnop\n'
b'qrstuwxyz\n')
with io.open(FN, mode='rb', buffering=4096) as f:
assert isinstance(f, io.BufferedReader)
f.readlines()
os.unlink(FN)
@markrwilliams
Copy link
Author

$ strace -e trace=open,read python /tmp/bio.py |& tail -3
open("thefile", O_RDONLY)               = 3
read(3, "abcdefgh\nijlkmnop\nqrstuwxyz\n", 4096) = 28
read(3, "", 4096)                       = 0

@markrwilliams
Copy link
Author

You should see the same behavior with buffering=1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment