File Mode

noun

say it: “FYLE MOHD” /ˈfaɪl moʊd/

The letter that tells open() what you plan to do with a file: "r" read (the default), "w" write (wiping the file first) or "a" add to the end.

What is a file mode?

A file mode tells open() what you plan to do: "r" read (the default), "w" write (wipes the file first), "a" add to the end.

with open("log.txt", "a") as file:
    file.write("User logged in\n")

In a sentence

  • “Choosing the file mode "w" erased the old scores.”
  • “The log opens with the file mode "a", so each run adds a line.”

Level: Apprentice · More Python terms at this level

Updated