#read file, this way no need to close reader
with open('test.txt') as my_file:
print(my_files.readlines())
#to write we specify second param for open
with open('test.txt', 'r+') as my_file:
text = my_file.write(':)')
print(text)
# r+ will over write the content, if file not exists throws exception
# w wil just replace whole content, this also creates a new file if file not exists.
#a appends the given content
#exceeptions
try:
with open('test.txt', 'r+') as my_file:
text = my_file.write(':)')
print(text)
except FileNotFountError as err:
print('File does not exist.')
raise err