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 moduleimport imdb# creating instance of IMDbia = imdb.IMDb()# idcode = "1187043"# getting informationmovie = ia.get_movie(code)# printing movie namecast = movie['cast']# printing actor nameprint(cast[0])# getting rolerole = cast[0].currentRole# printing roleprint(role) |
Output :
Aamir Khan Ranchoddas 'Rancho' Shyamaldas Chanchad / Phunsukh Wangdu
Another example
Python3
# importing the moduleimport imdb# creating instance of IMDbia = imdb.IMDb()# idcode = "4434004"# getting informationmovie = ia.get_movie(code)# printing movie namecast = movie['cast']# printing actor nameprint(cast[0])# getting rolerole = cast[0].currentRole# printing roleprint(role) |
Output :
Shahid Kapoor Tommy Singh



