Complete the attached MovieIO.py file, TODO statements included. Reading from attached .txt file, sample output is below
loading file.....
Not the correct format: NULL1984
Not the correct format: TOOMANYCOMMAS,,,,,,9999
Second element is not a number: ONE,ONE
Choose a movie to serialize:
1:2001(1968)
2:Metropolis(1927)
3:Blade Runner(1982)
4:Alien(1979)
5:The Wizard of Oz(1939)
6:ET(1982)
7:Star Wars(1977)
9:Close Encounters(1977)
10:King Kong(1933)
12:The Matrix(1999)
13:Back to the Future(1985)
15:Planet of the Apes(1968)
16:Brazil(1985)
Enter choice: ET
Enter a number
Enter choice: 2001
Number not in range: 2001
Enter choice: 1
2001 (1968) pickled to movie.p
MovieIO.py
class Movie():
def __init__(self,title="", year=0):
self.__title = title
self.__year = year
def parseLine(self, line):
# TODO: Set attributes based on line
# Create an Exception if it is not in the appropriate format:
# - (, separated -- 2 elements, and the second is a number)
line_array = line.split(',')
pass
def __str__(self):
return(self.__title +"("+str(self.__year)+")")
def main():
# TODO:
# Write a main method that reads in the MovieDataErr file line by line (must use the parseLine() function you write)
# It should handle the error raised by parseLine, by print a message about the line not being parseable and continue on
# Display a menu of all the valid Movies
#- (Must be flexible if I were to change the file used)
#- allow the user to choose a single file to output as a pickle
#- (MUST use numbers for choice <- errror handling REQUIRED, should work for ANY input)
# When the user chooses a file, output the chosen pickled object to a pickle file *.p
if __name__=="__main__":
main()
This assignment has been answered 5 times in private sessions.
Or buy a ready solution below.
© 2024 Codify Tutor. All rights reserved