Home » Python

Python File readable() Method with Example

Python File readable() Method: Here, we are going to learn about the readable() method, how to check whether a file is readable or not in Python?
Submitted by IncludeHelp, on December 18, 2019

File readable() Method

readable() method is an inbuilt method in Python, it is used to check whether a file stream is readable or not in Python.

Syntax:

    file_object.readable()

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is <class 'bool'>, it returns True if file stream is readable and returns False if files is not readable.

Example:

# Python File readable() Method with Example

# creating a file
myfile1 = open("hello1.txt", "w")

# checking whethet the file stream is 
# readable or not
print("myfile1.readable():", myfile1.readable())

# closing the file
myfile1.close()

# opening file in read mode
myfile1 = open("hello1.txt", "r")

# checking whethet the file stream is 
# readable or not
print("myfile1.readable():", myfile1.readable())

# closing the file
myfile1.close()

Output

myfile1.readable(): False
myfile1.readable(): True


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.