readable(): checks if a file object allows read operations

readable()
Returns boolean value True or False. Returns True if file is readable , otherwise False .

In file read mode ( r )

fob=open('data1.txt','r')
print(fob.readable()) # True

Using write mode

fob=open('data1.txt','w')
print(fob.readable()) # False

Using append mode

fob=open('data1.txt','a')
print(fob.readable()) # False

Using read and write

fob=open('data1.txt','+a')
print(fob.readable()) # True

Handling Non-Existent Files

When trying to open a file that doesn't exist, Python will raise an error. We can handle this with a try-except block:

try:
    fob = open('non_existent.txt', 'r')
    print(fob.readable())
except FileNotFoundError:
    print("File not found.")

Use Case: Checking Read Permissions

This can be useful in scenarios where a program needs to ensure read access before processing the file:

fob = open('data.txt', 'r')
if fob.readable():
    print("File is readable, proceeding with operations.")
else:
    print("File is not readable.")
writable()

File Append File Write
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer