IMDbPy "search_person" result cant be found in actors list in Python - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Game Development (https://python-forum.io/forum-11.html) +--- Thread: IMDbPy "search_person" result cant be found in actors list in Python (/thread-37773.html) |
IMDbPy "search_person" result cant be found in actors list in Python - tylerdurdane - Jul-20-2022 Have a list of actors. Asking the user to enter an actor name that exists in the list. Although entering an existing name in the list, the code says it does not exist in the list. The "counter" function shows 0, "boolean" operator is False. Why getting this error ? note: If I enter the actor name manually, the code can find the name in the list. So I tried to check the data type of "search_person" function and it returns "class". I tried to convert it to list by using list() function but also getting error. Asking for user input from imdb import Cinemagoer ia=Cinemagoer() actors=['Natalie Biggs','Daniel Crossley','Jaye Davidson','Tania Emery','Titus Forbes-Adam','Anthony Houghton','Jane Milligan'] # search for an actor in actors list people = ia.search_person(input('enter an actor/actress name that exists in the list above: ')) main_person=people[0] ia.update(main_person) print(actors.count(main_person)) print(main_person in actors)Output of asking to user:
If enter the "actor" name in the code like below, the code can find it in the list however I need to ask the user input like above from imdb import Cinemagoer ia=Cinemagoer() actors=['Natalie Biggs','Daniel Crossley','Jaye Davidson','Tania Emery','Titus Forbes-Adam','Anthony Houghton','Jane Milligan'] actor='Natalie Biggs' print(actors.count(actor)) Output for manually entering the actor name in the code (Successful)
RE: IMDbPy "search_person" result cant be found in actors list in Python - menator01 - Jul-20-2022 I don't know anything about imdb module but a basic python code wouls look something like actors=['Natalie Biggs','Daniel Crossley','Jaye Davidson','Tania Emery','Titus Forbes-Adam','Anthony Houghton','Jane Milligan'] # search for an actor in actors list print(', '.join(actors)) person = input('enter an actor/actress name that exists in the list above:\n>> ') print(actors.count(person)) print(person)
RE: IMDbPy "search_person" result cant be found in actors list in Python - DeaD_EyE - Aug-04-2022 The returned values from search_person is a list with instances of Person .To get the name, use the square-brackets or the get method on the person instance.The attribute item with the name is called name .Counting example: from imdb import Cinemagoer first_name = "Arnold" full_name = "Arnold Schwarzenegger" query = Cinemagoer() result = query.search_person(first_name) names = [actor["name"] for actor in result] for name in names: print(name) print(full_name, "in results:", names.count(full_name))You should read the docs: https://cinemagoer.readthedocs.io/en/latest/usage/quickstart.html Here another example wich uses user input to search for a person and listing all the movies. from imdb import Cinemagoer # https://pypi.org/project/IMDbPY/ # IMDbPY is now cinemagoer # pip install cinemagoer # https://cinemagoer.github.io/ def ask_one_actor(): user_input = input( f"Should only the first match of an actor listed (y/yes)?: " ).lower() if user_input in ("y", "yes"): return True else: return False def main(): query = Cinemagoer() show_only_one_actor = ask_one_actor() while True: actor = input("Please enter an actor name [q or whitespace to quit]: ").strip() # strip() removes whitespaces on left and right side of the str # condition to return which leaves the loop # a break could also be used, because there are # no further instructions are the while True loop if not actor.strip() or actor.lower() == "q": return # the method search_person returns a list # with persons (they are not str) # the result from query.search_person should be a list # index access should be possible for actor in query.search_person(actor): info_text = f"Query info for actor: {actor}" print(info_text) print("=" * len(info_text)) query.update(actor) for movie in actor.get_titlesRefs(): print(movie) # two newlines print("\n") if show_only_one_actor: break if __name__ == "__main__": try: main() except KeyboardInterrupt: print("\nQuit") |