Answer to Question #306338 in Python for XYZ

Question #306338

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.


1
Expert's answer
2022-03-05T07:48:20-0500
'''
    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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS