It looks like this:
What is a "file like object"?
What is exactly a file-like object in Python?
file-like objects are mainly StringIO objects, connected sockets and well.. actual file objects. If everything goes fine, urllib.urlopen() also returns a file-like objekt supporting the necessary methods.
file-like object
A synonym for file object.
file object
An object exposing a file-oriented API (with methods such as read() or write()) to an underlying resource. Depending on the way it was created, a file object can mediate access to a real on-disk file or to another type of storage or communication device (for example standard input/output, in-memory buffers, sockets, pipes, etc.). File objects are also called file-like objects or streams.
There are actually three categories of file objects: raw binary files, buffered binary files and text files. Their interfaces are defined in the io module. The canonical way to create a file object is by using the open() function.
io — Core tools for working with streams
The io module provides Python’s main facilities for dealing with various types of I/O. There are three main types of I/O: text I/O, binary I/O and raw I/O. These are generic categories, and various backing stores can be used for each of them. A concrete object belonging to any of these categories is called a file object. Other common terms are stream and file-like object.
What is being flushed?
The data held in the output buffer.
When would one use flush as opposed to just individually resetting the input/output buffers?
There is data that has been output(write()
), and it will be called before closing.
flush()
has nothing to do with input buffer or reset_input_buffer()
.
flush()
has a different function than reset_output_buffer()
.
flush()
sends all the data in the output buffer to the peer, while reset_output_buffer()
discards the data in the output buffer.
reset_output_buffer()
Clear output buffer, aborting the current output and discarding all that is in the buffer.
Note, for some USB serial adapters, this may only flush the buffer of the OS and not all the data that may be present in the USB part.