Professional Documents
Culture Documents
File and Exceptions
File and Exceptions
.
File
• Python has a built-in open() function to open a file.
• This function returns a file object, also called a handle, as it is
used to read or modify the file accordingly.
• File can be open in read mode(r),write(w),append(a),r+(read&
write)
• f = open("test.txt“,’r’)
f.tell() :To find current position
f.seek(0) :To reach desired position
f.readline()
f.read()
f.close()
Exception Handling
• Error in Python can be of two types Syntax
Error and Exceptions.
• Errors are the problems in a program due to
which the program will stop the execution.
• Exceptions occurs during the run time which
interrupts the normal flow of execution of the
program.
Try and Except Statement
except zerodivision:
print("Input value is zero, try again!")
else:
print()