Python Tutorial Python Advanced Python References Python Libraries

Python - File writable() Method



The Python writable() method is used to check whether the specified file is writable or not. It returns true if the specified file is writable, else returns false. A file is writable if it is opened using write or append mode.

Syntax

file.writable()

Parameters

No parameter is required.

Return Value

Returns True if the file is writable, else returns False.

Example: Check a file, writable or not

In the example below, Python file writable() method is used to check if the given file is writable or not.

MyFile = open("test.txt", "w")
print(MyFile.writable())
MyFile.close()

MyFile = open("test.txt", "r")
print(MyFile.writable())
MyFile.close()

MyFile = open("test.txt", "a")
print(MyFile.writable())
MyFile.close()

The output of the above code will be:

True
False
True

❮ Python File Handling Methods