Python IMDbPY - 检查人是否是电影的一部分
在本文中,我们将了解如何检查某个人是否是电影的一部分,很多人都在制作电影,有时我们不知道一个人是否在那部电影中,但是使用我们可以检查运算符的帮助in
Implementation steps :
1. Get the movie data with the help of get_movie method
2. Get the person data with the help of get_person method
3. Using in operator check if person was part of movie or not
4. Show the result
下面是实现
# importing the module
import imdb
# creating instance of IMDb
ia = imdb.IMDb()
# ID
code = "4434004"
# getting movie
movie = ia.get_movie(code)
# person id
code2 = "1372788"
# getting person
person = ia.get_person(code2)
# printing movie object
print(movie)
# printing person object
print(person)
print("===============")
# checking if person is in the movie or not
if person in movie:
print("Yes !!")
else:
print("No !!")
输出 :
Udta Punjab
Shahid Kapoor
===============
Yes!!
另一个例子
# importing the module
import imdb
# creating instance of IMDb
ia = imdb.IMDb()
# ID
code = "1187043"
# getting movie
movie = ia.get_movie(code)
# person id
code2 = "1372788"
# getting person
person = ia.get_person(code2)
# printing movie object
print(movie)
# printing person object
print(person)
print("===============")
# checking if person is in the movie or not
if person in movie:
print("Yes !!")
else:
print("No !!")
输出 :
3 Idiots
Shahid Kapoor
===============
No!!