【问题标题】:IMDbPY handling None objectIMDbPY 处理无对象
【发布时间】:2021-10-22 19:15:41
【问题描述】:

我正在尝试从 IMDbPY 中提取有关电影摄影师的数据,但遇到了一个空对象。我不确定如何处理代码中的 None 对象。有人可以帮帮我吗?

这是我到达的地方。

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)



代码根本不起作用,我得到的只是:

鲍里斯·考夫曼 []


TypeError Traceback(最近一次调用最后一次) 在 () 21 22 ---> 23 imdblistdop(项目) 24 25

in imdblistdop(myList, *args) 10 代表 myList 中的 x: 11 电影 = ia.get_movie(x) ---> 12 电影摄影师 = movie.get('cinematographers')[0] 13cinematographer2 = movie.get('cinematographers') 14 版(电影摄影师)

TypeError: 'NoneType' 对象不可下标

【问题讨论】:

    标签: python imdbpy


    【解决方案1】:

    cinematographer 是一个列表。这意味着您可以使用其索引指向列表中的条目。示例:cinematographer[2]。您可以使用字符串指向列表中的条目。

    【讨论】:

    • 兄弟我的代码有错误。在这里编辑时,我搞砸了。
    • 它会解析第一个filmid,然后就崩溃了
    • 我尝试处理错误的方式有错误?
    • cinematographer = movie.get('cinematographers')[0] 之前添加行 print(movie.get('cinematographers')) - 你会得到什么?
    • [] Boris Kaufman [] [] 无 在 imdblistdop(myList, *args) 11 电影 = ia.get_movie(x) 12 打印(movie.get('cinematographers')) ---> 13 电影摄影师 = movie.get('cinematographers')[0] 14 cinematographer2 = movie.get('cinematographers') 15 print(cinematographer) TypeError: 'NoneType' object is not subscriptable
    猜你喜欢
    • 1970-01-01
    • 2016-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-26
    • 2010-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多