The readable() function from File Methods in Python is used to check if the file can be read. It returns True if the file can be read, and False otherwise.
Parameter Values
This function does not accept any parameters.Return Values
The readable() method returns a bool, indicating if the file stream can be read.
How to Use readable() in Python
Example 1:
Return True if the file is readable, False otherwise.
file = open('example.txt', 'r')
print(file.readable())
file.close()
Example 2:
Return True if the file is readable, False otherwise.
with open('example2.txt', 'r') as file:
print(file.readable())
Example 3:
Return True if the file is readable, False otherwise.
file = open('example3.txt', 'w')
print(file.readable())
file.close()