Member-only story

Find director of a movie using Python

Python Coding
2 min readOct 21, 2024

--

from imdb import IMDb

ia = IMDb()
movie_name = input("Enter the movie name: ")
movies = ia.search_movie(movie_name)

if movies:
movie = movies[0]
ia.update(movie)
directors = movie.get('directors')
if directors:
print("Director(s):")
for director in directors:
print(director['name'])
else:
print("No director information found.")
else:
print("Movie not found.")

Here’s an explanation of the code step-by-step:

1. from imdb import IMDb

This imports the IMDb class from the imdb module, which is part of the IMDbPY library. The IMDb class provides methods to interact with the IMDb database.

2. ia = IMDb()

This creates an instance of the IMDb class. The ia object will be used to query the IMDb database.

3. movie_name = input("Enter the movie name: ")

This prompts the user to input the name of the movie they want to search for. The movie title is stored in the movie_name variable.

4. movies = ia.search_movie(movie_name)

This uses the search_movie() method of the IMDb object ia to search for movies matching the name provided by the user. The…

--

--

Python Coding
Python Coding

Written by Python Coding

Learn python tips and tricks with code I Share your knowledge with us to help society. Python Quiz: https://www.clcoding.com/p/quiz-questions.html

No responses yet