# with statement

# with statement mainly used for the following operations
# files
# locks
# network connection
# db connection
# ...

# =========================================

# example1
# we know that we have to close the file once the operations have been done
# but with the 'with' statement, it would be automatically closes the file
# no need to write the file.close()

with open('myFile.txt', 'w') as file:
    file.write('Hello world!')

# above example1 is equivalent to the following block of code
# file = open('myFile.txt', 'w')
# try:
#     file.write('Hello world!')
# finally:
#     file.close()

# =========================================
