When the covid-19 situation arose in early 2020 your small team of developers quickly found out...

80.2K

Verified Solution

Question

Programming

When the covid-19 situation arose in early 2020 your small teamof developers quickly found out how much questions you used to askeach other in person. Now that you all work from home most of thetime you have resorted to using online chat instead. But this hasresulted in that you all have to go back and read endless chat logswhen you forget what you agreed on earlier.

To remedy this problem, you have decided to write a small scriptthat reads a log file and then allow you to search for all messagessent by one user. To make the script a bit more versatile you havedecided that the path to the log file shall be sent as a commandline argument to the script. As everyone in the team is a bitsloppy when typing, the script needs to have error handling thatclearly informs the user in case the specified path to the log filedoes not exist. The format of the error message can be seen in thisexample:

Error: The file ‘/Users/nna/messages.txt’ could not be found.

The script shall have a main function, a function for readingfrom the log file, and a function for formatting and displaying amessage on the screen. There are some rules for how thefile-reading function and the display function shall work:

read_file(filename)
Shall read the file specified by the parameter filename and createa list of tuples that is then returned. Each tuple shall consist ofa name and a message. In the file each message takes up two rows,where the first row contains the senders name, and the second rowcontains the text of the message. Each log file can of coursecontain many messages sent by many different persons.

display_entry(name, message)
Shall use the two parameters to display a formatted output on thescreen. The output shall follow this format:
[name] --> message

All other functionality needed in the script shall be added inthe main function, this includes but is not limited to asking whatname to search the log file for.

Answer & Explanation Solved by verified expert
4.0 Ratings (785 Votes)
PLEASE GIVE IT A THUMBS UP I SERIOUSLY NEED ONE IF YOUNEED ANY MODIFICATION THEN LET ME KNOW I WILL DO IT FORYOUimport sysimport osdef readfilefilename messages f openfilename r lines freadlines templist 0 1 for i in rangelenlines ifi    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students