Two Mark Answers
Two Mark Answers
Two Mark Answers
7) How do you handle the exception inside a program when you try to
open a non-Existent file?
try:
f=open("new.txt",'r')
except IOError:
print("No Such File")
else:
print("File Opened")
8) Difference between write and append mode.
Write Mode Append Mode
• Open a file to write data, if file • Open a file to append data, if file
does not exist, it creates a new does not exist, it creates a new
file file
• It overwrites the existing data • It adds the data at the EOF
• Cursor placed in the beginning • Cursor placed in the End of the
of the file File.
• f = open (“new.txt”, ‘w’) • f = open (“new.txt”, ‘a’)