Python IMDbPY – Getting person ID from searched persons

In this article we will see how we can get the person id from searched person, person id is basically unique id given to each person names can be same of some people but id will be distinct. We use search_person method to get people with the same name.

In order to get person id we use personID method.

Syntax : persons[0].personID

Here persons is the list of person returned by search_person and persons[0] refer to first element in list

Argument : It takes no argument.



Return : It return string which is Person ID

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()
   
# name 
name = "Ayushmann Khurrana"
   
# searching the name 
search = ia.search_person(name)
  
  
# loop for printing the name and id
for i in range(len(search)):
      
    # getting the id
    id = search[i].personID
      
    # printing it
    print(search[i]['name'] + " : " + id )

chevron_right


Output :

Ayushmann Khurrana : 4731677

Another example

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing the module
import imdb
   
# creating instance of IMDb
ia = imdb.IMDb()
   
# name 
name = "Pankaj Tripathi"
   
# searching the name 
search = ia.search_person(name)
  
  
# loop for printing the name and id
for i in range(len(search)):
      
    # getting the id
    id = search[i].personID
      
    # printing it
    print(search[i]['name'] + " : " + id )

chevron_right


Output :

Pankaj Tripathi : 2690647
Pankaj Tripathi : 11337375
Sankalp Raj Tripathi : 9704712

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




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.