# With is used for better and more readable file handling.
# Instead of having to open and close the file:
file_handler = open('path', 'w')
file_handler.write('Hello World!')
file_handler.close()
# You can use with which will close the file for you at the end of the block:
with open('path', 'w') as file_handler:
file_handler.write('Hello World!')
# Another common use is with pickle files:
with open('pickle_path.pkl', 'rb') as file_handler:
file_contents = pickle.load(file_handler)