Using Python 3.11 for a school assignment. The assignment instructs me to build a Movie class with title, genre, director, and year, with getters for these. Then we build a StreamingService class with name and catalog parameters. Catalog initializes as an empty dictionary. Getter method for name and catalog, add/delete movie from catalog. Finally, the last portion is to build a StreamingGuide class with no parameters and streaming_services initializing as an empty list. Add/delete methods to get StreamingService objects into the Guide class, and the crown jewel: where_to_watch method, which takes a movie and finds which streaming services that movie is in. All data members are to be private.
The first two data classes work just fine. All things are as they should be when I run each method. The Guide's add method works fine. Deleting the services is where I get tripped up, along with formatting the final where_to_watch results.
My delete service method under the Guide class looks like this:
def delete_streaming_service(self, stream_serv_object):'''Delete streaming service object from streaming guide object''' service_name = StreamingService.get_name(stream_serv_object) if stream_serv_object in self._streaming_services: del self._streaming_services[stream_serv_object]
The delete method test code provided in the assignment looks like this:
stream_guide.delete_streaming_service('Hula')
'Hula' being one of the fake streaming service names given in the testing code. However, when I test this all as written, the delete_streaming_service method returns "AttributeError: 'str' object has no attribute '_name'", and points me to the get_name method of StreamingService class. When called on its own, the get_name method works; it's only in this function that it throws this error.
The second error I get is similar. The assignment instructions are clear that the where_to_watch results are to be a list starting with [ 'Movie Title (Year)'] and then print the services the movie was found on. The code I have as of now is:
def where_to_watch(self, movie_object):'''Find which streaming services contain the parameter movie object''' found_on = [] #movie_title = Movie.get_title(movie_object) #movie_year = Movie.get_year(movie_object) #movie_info = str(movie_title +'('+ movie_year +')') #found_on.append(movie_info) for service in self._streaming_services: for movie in StreamingService.get_catalog(service): if movie_object in movie: found_on.append(service.get_name()) else: continue return found_on
The line provided to test this method is as follows:
search_results = stream_guide.where_to_watch('The Seventh Seal')print(search_results)
The where_to_watch method works fine as is with those 4 lines commented out, but is clearly not in the desired format. When I un-comment the lines after found_on and before the loop, it throws "AttributeError: 'str' object has no attribute '_title'. Did you mean: 'title'?" which is an issue, because as stated before, all data members of each class are meant to be private. What am I doing wrong?