all Python 3ioterm
io.FileIO
binary streams
A raw (unbuffered) binary stream to a file by name or descriptor; the low-level base on which open() builds buffering.
Syntax
io.FileIO(name, mode='r')
You rarely construct it yourself: open(path, 'rb', buffering=0) hands you exactly a FileIO, and a normal open() stacks buffering and text decoding on top of one. The classic trap with a raw stream is that read(n) issues a single system call and may legitimately return fewer than n bytes long before EOF, so read with readall() or loop until you get an empty result.
Examples
import io
import os
print(issubclass(io.FileIO, io.RawIOBase)) # → True
f = io.FileIO(os.devnull, 'r')
print(f.mode) # → rb
print(f.readable(), f.writable()) # → True False
print(f.read()) # → b''
f.close()
print(f.closed) # → True
b = open(os.devnull, 'rb')
print(type(b.raw).__name__) # → FileIO
b.close()
See also
Open in the full glossarydocs.python.orgReport an inaccuracy