open()

noun

say it: “OH-pun” /ˈoʊpən/

The Python function that opens a file so a program can read it or write to it, given the file's name and, optionally, a mode such as "w" for writing.

What does open() do?

open() opens a file so your program can read from it or write to it.

with open("notes.txt") as file:
    print(file.read())

In a sentence

  • “open() with "a" added each new run to the end of the club's log file.”
  • “She used open() in a with block so the file closed by itself.”

Level: Apprentice · More Python terms at this level

Updated