Monday, June 15, 2026
HomeLanguagesPython IMDbPY – Getting role of person in the movie

Python IMDbPY – Getting role of person in the movie

In this article we will see how we can get the role of person the movie, we know movie object act similar to dictionary. IMDb data base has lot of information i.e details about the persons work in the movie and what was there role in that movie.
 

In order to the role of the person we have to do the following –
1. Get the movie object with the help of get_movie method 
2. Get the cast details from the movie object 
3. Get the role of desired person with the help of currentRole method 
4. Show the result 
 

Below is the implementation 
 

Python3




# importing the module
import imdb
 
# creating instance of IMDb
ia = imdb.IMDb()
 
# id
code = "1187043"
 
# getting information
movie = ia.get_movie(code)
 
# printing movie name
cast = movie['cast']
 
# printing actor name
print(cast[0])
 
# getting role
role = cast[0].currentRole
 
# printing role
print(role)


Output : 
 

Aamir Khan
Ranchoddas 'Rancho' Shyamaldas Chanchad / Phunsukh Wangdu

Another example 
 

Python3




# importing the module
import imdb
 
# creating instance of IMDb
ia = imdb.IMDb()
 
# id
code = "4434004"
 
# getting information
movie = ia.get_movie(code)
 
# printing movie name
cast = movie['cast']
 
# printing actor name
print(cast[0])
 
# getting role
role = cast[0].currentRole
 
# printing role
print(role)
    


Output : 
 

Shahid Kapoor
Tommy Singh

 

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS