Python - File readable() Method
The Python readable() method is used to check whether the specified file is readable or not. It returns true if the specified file is readable, else returns false. A file is readable if it is opened using read mode.
Syntax
file.readable()
Parameters
No parameter is required.
Return Value
Returns True if the file is readable, else returns False.
Example: Check a file, readable or not
In the example below, Python file readable() method is used to check if the given file is readable or not.
MyFile = open("test.txt", "a") print(MyFile.readable()) MyFile.close() MyFile = open("test.txt", "w") print(MyFile.readable()) MyFile.close() MyFile = open("test.txt", "r") print(MyFile.readable()) MyFile.close()
The output of the above code will be:
False False True
❮ Python File Handling Methods