file mode

The second argument to open(), which says how the file will be used: "r" read, "w" write from scratch, "a" append, with "b" added for bytes.

Opening an existing file in "w" mode erases its contents immediately and without warning.

In more detail

"w" empties an existing file straight away, so opening the wrong name in write mode destroys its contents. "a" adds to the end instead. Text modes return strings; binary modes such as "rb" return bytes.

Related terms

Taught in

References