The returned values from
To get the name, use the
The attribute item with the name is called
Counting example:
Here another example wich uses user input to search for a person and listing all the movies.
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/lat...start.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")
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!