Write program parse_fish.py (practice test for exam) Open the file…

Question Answered step-by-step Write program parse_fish.py (practice test for exam) Open the file…  Write program parse_fish.py (practice test for exam)Open the file using the the first command line argument as the filename and parse the contents to check for correctness. There must be at least one fish in the file.  Missing command line arguments will print a message “Usage python3 parse_fish.py ” and terminate the program with return code 1 .  Handle exceptions for the cases:  the file does not exist, and terminate the program with exit code 2  for all other exceptions when opening or reading the file, terminate the program with exit code 3 During the parsing process, make and throw exceptions for error cases:  missing field – when one of the 6 fields are missing or unexpected -> Exception(” Missing field: “) ,  invalid data – when the data is absent, or does not fit the type or the range, includes missing data -> Exception(” Invalid data: “)  empty line expected – no empty line found after one fish record. Exception(” Empty line expected”)  Where is the line number of the input text file and is an appropriate description made by you to inform about the specifics of the error.  If there are two or more exceptions that could be created, you must create exceptions in the order of reading the file contents.  When you throw the Exception from an errors described above, do not catch them and allow the program to stop.  If there are no errors. Print ” lines read succcessfully” and return exit code 0 , where n is the number of lines in the file.  Restrictions and notes Only import sys is allowed. No modules or imports allowed  Do not catch the exceptions that you need to create. However, you may need other exception handling for identifying when to make an exception.  Case sensitivity for fields need not be matched. Additional whitespace should be ignored  split() , find() , strip() , upper()/lower() and slices are useful.  Consider creating your own helper functions to break the problem into smaller peices  All input text line numbers start from 1 (not zero!)  Reading from a text file may contain new line characters  exit(0) – is necessary on successful parsingImage transcription textExample Samme?m Fish number: 1 Type: Bony Name: Fin Age: 32 weight: 20 Hunger: ?5Fish number: 2 Type: Bony Name: Misty Age: 14 weight: 11 Hunger: 41 Fish number: 3 Type:Cartilaginous Name: Mejo Age: 15 weight: 10 Hunger: 59 … Show moreImage transcription textA fish has attributes Fish number:Type: Bony or Cartilagino… Show more… Show moreImage transcription textValid text file Input file: See exampleabove Output: 21 lines readsuccessfully Invalid text fil… Show more… Show more  Computer Science Engineering & Technology Python Programming INFO 1110 Share QuestionEmailCopy link Comments (0)

Leave a Comment

Your email address will not be published. Required fields are marked *