User Program Communication
Object Oriented Programming
With Statement in Python
Used to execute code with an unmanaged resource that may raise an exception. The with statement manages the resource, using it if successful and removing it when the block finishes executing.
with resource as resource_var_name: #do something with resource
An example of a resource that may raise an exception is a file stream.
with open('input.txt', 'r') as f: data = f.read()