Overview:
The TextIOWrapper is an input and output stream that specializes in handling text encoding and decoding while performing write and read operations. The stream supports both input and output operations.
TextIOWrapper supports buffered input and output. Buffering refers to the technique of gathering some amount of bytes before writing it to the destination. TextIOWrapper gathers the contents up to the occurrence of a new line character before making a call to flush. Buffering can be turned-off if write_through is enabled.
The example uses a BytesIO object as the underlying buffer.
Example:
|
# Example Python program that writes to and # Create a buffer # Create a stream that handles text # Write to the TextIOWrapper and flush it when done # While writing the file pointer moved... # Read from TextIOWrapper using iterator protocol print("Encoding used:") print("Write_through:") print("Line buffering:") print("Default buffer size:")
|
Output:
|
Hello
World Encoding used: |