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

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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
  
# printig role
print(role)

chevron_right


Output :

Aamir Khan
Ranchoddas 'Rancho' Shyamaldas Chanchad / Phunsukh Wangdu

Another example

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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
  
# printig role
print(role)
     

chevron_right


Output :

Shahid Kapoor
Tommy Singh



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.