我遇到以下错误:
TypeError: cannot unpack non-iterable NoneType object
当我调用此函数时:
# current client's schedule (dict)
clientSchedule = client
# value to let the program know if scheduling is 'finished'
t1_processDone = False
# the function itself, variable types are as follows:
# client_name is a string, client_ID is an int,
# client_team is a list, clientSchedule is a dict,
# t1_processStatus is dynamically typed (True, False or None)
clientSchedule, t1_processDone = insert_t1(client_name, client_ID,
client_team, clientSchedule,
t1_processStatus)
此行发生错误:
clientSchedule, t1_processDone = insert_t1(client_name, client_ID...)
client_sch
是一个不为空的字典。从我的研究中,我发现当函数返回None
时会发生此错误,并且该值无法迭代。但是在这种情况下,我期望并返回一个元组。
答案 0 :(得分:0)
首先,执行该行时不会出现您说的错误:
return client_sch, True
因为该行未进行任何拆包。如果您是指insert_t1
通过该行返回时,在代码的最后一行出现错误,则更有意义。但是,如果这是真的,那么您不应该得到所得到的错误。这段代码运行良好:
def insert_t1(a, b, c, d, e):
client_sch = None
return client_sch, True
def main():
client = ""
client_name = ""
client_ID = ""
client_team = ""
t1_processStatus = ""
# current client's schedule (dict)
clientSchedule = client
# value to let the program know if scheduling is 'finished'
t1_processDone = False
# the function itself, variable types are as follows:
# client_name is a string, client_ID is an int,
# client_team is a list, clientSchedule is a dict,
# t1_processStatus is dynamically typed (True, False or None)
clientSchedule, t1_processDone = insert_t1(client_name, client_ID,
client_team, clientSchedule,
t1_processStatus)
main()
请注意,即使client_sch
为None
,此方法也有效。另一方面,如果您的insert_t1
函数返回了None
,则会收到您看到的错误。只需在上面的代码中将return client_sch, True
替换为return None
,就可以准确地报告错误。
因此,我猜测您在此处呈现的内容与您的实际情况不符。如果还没有,我建议您寻找insert_t1
可以返回的其他方式,并可能在调试器中运行您的代码。如果您遇到错误,则会得到您所说的话,那么我提供的代码也应该为您提供该错误。如果是这样,则说明发生了一些奇怪的事情。如果没有,那么显然您提供的内容中看不到正在发生的事情。