Function Details: read

Description


Read at most size characters from stream. If size is negative or None, read until EOF.


Extended Description


The read() method reads and returns the specified number of characters from the file, or the entire file if size is not specified or is negative. It's important to note that for text files, the number of characters may not correspond exactly to the number of bytes, due to character encoding.


Function Signature



Module: io

Class: TextIOWrapper

Parameters



Parameter List


  • size: int

Return


Returns a string containing the characters read. Returns an empty string if EOF is hit immediately.


Return Type


str

Output

Explanation

This example demonstrates the basic usage of read(). It reads the entire contents of the file.