IMDbPY handling None object

43 Views Asked by At

I'm trying to pull data about cinematographers from IMDbPY and i'm encountering a null object. I'm not sure how to deal with that None object in the code. Could someone help me out please?

here's where I have reached.

from imdb import IMDb, IMDbError
ia = IMDb() 
itemdop = ''
doplist = []


items = ["0050083", "6273736", "2582802"]

def imdblistdop(myList=[], *args):
    for x in myList:
      movie = ia.get_movie(x)
      cinematographer = movie.get('cinematographers')[0]
      cinematographer2 = movie.get('cinematographers')
      print(cinematographer)
      print(doplist)
      try:
            itemdop = cinematographer['name']
            doplist.append(itemdop)
      except KeyError as ke:
            print('Nope!')


imdblistdop(items)



The code is not working at all and all i get is this:

Boris Kaufman []


TypeError Traceback (most recent call last) in () 21 22 ---> 23 imdblistdop(items) 24 25

in imdblistdop(myList, *args) 10 for x in myList: 11 movie = ia.get_movie(x) ---> 12 cinematographer = movie.get('cinematographers')[0] 13 cinematographer2 = movie.get('cinematographers') 14 print(cinematographer)

TypeError: 'NoneType' object is not subscriptable

1

There are 1 best solutions below

9
balderman On

cinematographer is a list. It means that you can point to an an entry in the list using its index. Example: cinematographer[2]. You can not use a string to point to an entry in the list.