Skip to content

Instantly share code, notes, and snippets.

View brannerchinese's full-sized avatar

David Branner brannerchinese

View GitHub Profile
@brannerchinese
brannerchinese / README.md
Last active August 20, 2016 20:20 — forked from anomalyjane/Vocab_quiz.py
A vocabulary quiz written for Python 2

README

Some Python tools.

Context manager for file I/O

A "context manager" imposes a beginning and end on some process that can cause problems if interrupted midway through. In the case of file I/O, if a file is opened for reading or writing and then not closed properly, it can be left in a locked state. A context manager (initiated by the with keyword) ensure that the file is closed in any case. Example

with open('questions_and_answers.json', 'r') as f: