Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Context Manager examples

A few examples where context managers can be useful:

  • Opening a file - close it once we are done with it so we don't leak file descriptors.

  • Changing directory - change back when we are done.

  • Create temporary directory - remove when we are done.

  • Open connection to database - close connection.

  • Open SSH connection - close connection.

  • More information about context managers