.writable()

The .writeable() file method allows the user to check if a file is writable or not. The function will return True if the file is writable and accessed in append or write mode, and False if it was accessed in read mode.

Syntax

file.writable()

Example 1

Use .writable() to check if the gullivers_travels.txt file is writable:

f = open("gullivers_travels.txt", "a")
f.writable()

The .writable() method will return True here.

Example 2

Use .writable() to check if the gullivers_travels.txt file is writable:

f = open("gullivers_travels.txt", "r")
f.writable()

The .writable() method will return False here.

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn Python on Codecademy

Contributors