I'm doing a library for DVD-movies and I'm trying to figure out how to search different categories like director, title, actor etc. (which are all variables in a DVD-class).
Previously I did like this:
However, I want to avoid using the same code, and would rather have just one method. This is as far as I've gotten:
However, then it just searches through the 'movies[i].title' string and it also gives me
Does anyone have a fairly quick sollution to this? I really appreciate the help! Sorry if something similar has been posted, I couldn't find anything. If it has, please direct me there.
Previously I did like this:
Code:
def search(self):
print '\nWhat do you wish to search for?\n'
print ' 1. Search for Title.'
print ' 2. Search for Year.'
print ' 3. ...'
choice = raw_input('\nMenu choice: ')
if choice == '1':
search_term = raw_input('\nSearch for a title: ')
print '\nResult: \n'
result = False
for i in range (len(movies)):
if search_term in movies[i].title:
print movies[i]
result = True
if result == False:
print 'No results found. \n'
user_library.search()
if choice == '2':
search_term = raw_input('\nSearch for a year: ')
print '\nResult: \n'
result = False
for i in range (len(movies)):
if search_term in movies[i].year:
print movies[i]
result = True
if result == False:
print 'No results found. \n'
user_library.search()
Code:
def search_menu(self):
print '\nWhat do you wish to search for?\n'
print ' 1. Search for Title.'
print ' 2. Search for Year.'
print ' 3. ...'
choice = raw_input('\nMenu chocie: ')
if choice == '1':
user_library.search('movies[i].title')
def search(self, search_category):
self.search_category = search_category
search_term = raw_input('\nSearch: ')
print '\nResult: \n'
result = False
for i in range (len(movies)):
if search_term in search_category:
print movies[i]
result = True
if result == False:
print 'No results found. \n'
user_library.search()
Code:
TypeError: search() takes exactly 2 arguments (1 given)
Comment