python - 我得到: TypeError: cannot unpack non-iterable NoneType object,但我正在返回一个元组
问题描述
我收到以下错误:
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
,并且该值无法迭代。但在这种情况下,我期待并返回一个元组。
解决方案
首先,您在执行该行时不会收到您所说的错误:
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
is 也是如此None
。另一方面,如果你的insert_t1
函数 WAS 返回None
,你会得到你所看到的错误。只需在上面的代码中替换return client_sch, True
为return None
,您就会得到您报告的错误。
所以我猜你在这里展示的内容与你的实际情况不符。如果您还没有,我建议您寻找其他insert_t1
可以返回的方法,并可能在调试器中运行您的代码。如果你得到你所说的错误,那么我提供的代码也应该给你那个错误。如果是这样,那么就会发生一些奇怪的事情。如果没有,那么显然有一些事情在您提供的内容中不可见。
推荐阅读
- javascript - Google Map Places API 未加载 React
- c# - 如何将对象属性传递给报告(RDLC)C#
- excel - VBA:匹配来自不同工作簿的单元格
- javascript - 反应脚本中的文本颜色变化
- .htaccess - htaccess 内部屏蔽重定向
- powerbi - 基于列中不同值的 DAX 度量计算
- c - 仅在输入出生年份时,如果您年满 16 岁,则使用函数 get_input 和 validate_input 打印您是否符合条件的 C 程序
- performance - 为什么pypy3比python慢
- python - 由 None 分隔的单独数组元素组
- ubuntu - 在 AWS EC2 Ubuntu 中设置 kafka.service 和 zookeeper.service