close()

The file method that finishes with a file, writing out any buffered data and freeing it for other programs.

In more detail

Text written to a file may sit in a memory buffer until close, so a program that forgets to close can leave the file empty or incomplete. A with statement closes the file for you, even if an error happens.

Related terms

Taught in

References