0

我在同一个功能上一直出错,我不知道为什么。我以为我第二次修复它,但不明白为什么这仍然是任何问题。错误会不时弹出。

这是我的第一个错误,但我修复了它。

  File "running.py", line 332, in run
TypeError: argument of type 'NoneType' is not iterable ================================================================================
05Oct 03:06:48: Exit status: 1

这是我当前的代码

def get_notifyees(jobdef):
    origNotifyeesList = jobdef['notifyees'] if isinstance(jobdef['notifyees'], list) or jobdef['notifyees'] is None else [jobdef['notifyees']]
    origNotifyeesList = origNotifyeesList if origNotifyeesList is not None else []
    notifyeesList = []
    for notifyee in origNotifyeesList:
        if 'noreply' not in notifyee:
            notifyeesList.append(notifyee)
    return notifyeesList   

但我现在收到此错误

File "running.py", line 337, in get_notifyees
KeyError: 'notifyees'
================================================================================
10Oct 01:53:03: Exit status: 1
4

1 回答 1

0

你有:

origNotifyeesList = jobdef['notifyees'] if isinstance(jobdef['notifyees'], list) or jobdef['notifyees'] is None else [jobdef['notifyees']]

这将引发KeyErrorif notifyeesis not a key in jobdef。您可以捕获异常,或者您可以检查if 'notifyees' in jobdef您尝试使用密钥的位置。

于 2014-10-10T13:04:39.550 回答