Your college has a logging system for students internet activities. Daly logs 1000 of entries and stored in internet file as 12 lines. One day the IT administrator want to analyse for recent activities done by students, so he needs to access log entries from bottom first. Write a python function file-end(file-name, n) which accepts file name, number of lines it will read from last and return them in string as shown in example. Also, write the exception handling code to show the proper message. Also, write the exception handling code to show the proper message. Do not use input function and give input values in fixed form.
'''
Your college has a logging system for students internet activities.
Daly logs 1000 of entries and stored in internet file as 12 lines.
One day the IT administrator want to analyse for recent activities
done by students, so he needs to access log entries from bottom first.
Write a python function file-end(file-name, n) which accepts file name,
number of lines it will read from last and return them in string as
shown in example. Also, write the exception handling code to show the
proper message. Also, write the exception handling code to show the
proper message. Do not use input function and give input values in fixed form.
'''
def file_end(fname, n):
file = open(fname,"r")
try:
with open(fName, 'r') as f:
s = (file.read()).split("\n")
for r in range(0,n):
print(s[r])
except IOError:
print ("Could not read file:", fName)
Comments
Leave a comment