How can you read the entire content of a file and safely handle the case when the file might not exist, printing "File missing" if so?
Atry:
file = open('data.txt', 'w')
content = file.read()
except IOError:
print('File missing')
Btry:
with open('data.txt', 'r') as f:
content = f.read()
except FileNotFoundError:
print('File missing')
Cif os.path.exists('data.txt'):
with open('data.txt', 'r') as f:
content = f.read()
else:
print('File missing')
Dwith open('data.txt', 'r') as f:
content = f.read()
if not content:
print('File missing')