python"TypeError: 'NoneType' object is not iterable"错误解析

尊重原创博主,原文链接:https://blog.csdn.net/dataspark/article/details/9953225

【解析】

一般是函数返回值为None,并被赋给了多个变量。

实例看下:

c=0def test():
    if c == 1:
        a = b = 1
        return a, b

a, b = test()

使用 a, b = test()调用时,就会报错:TypeError: ‘NoneType‘ object is not iterable

在Python判断语句中,当if条件不满足并且没有else的时候就会返回None,就算是没有return 也会默认返回None

本例中a,b 都赋予了None值,就出现了上述错误。

所以函数返回值一定要考虑到条件分支的覆盖。

本人是正在读的学生,如有错误还请各路大神慷慨指出,谢谢!

python"TypeError: 'NoneType' object is not iterable"错误解析

原文地址:https://www.cnblogs.com/pangzx/p/9038882.html

时间: 2024-12-10 09:13:43

python"TypeError: 'NoneType' object is not iterable"错误解析的相关文章

Python“TypeError: 'NoneType' object is not iterable"的原因

本来不想说的,但是发现大家都遇到了该问题,由于该问题编译器提示较模糊,一般仅仅说for循环的参数没有定义,不能迭代. 具体如下截图: 其实问题不是参数,而是我们在使用参数的过程中错误了,大家可以看图上的提示就能够明白,192.168.1.1/32和192.168.1.1/24的区别,请大家以后在python中遇到类似问题是不要慌张. Python"TypeError: 'NoneType' object is not iterable"的原因,布布扣,bubuko.com Python

python TypeError: 'NoneType' object is not iterable

list(set(map(lambda tp_id : tp_id if not ('#' in tp_id) and len(tp_id.strip().replace('\n', '')) > 0else None, open('tp_list.txt').readlines()).sort())) 为了练习map,想着把一个循环写成一行代码. 结构跑程序时出了一个问题:TypeError: 'NoneType' object is not iterable. 找了半天错误(写成一行代码在这

python TypeError: 'builtin_function_or_method' object is not iterable keys

statinfo = os.stat( OneFilePath ) if AllFiles.has_key( statinfo.st_size ): OneKey = AllFiles[ statinfo.st_size ] OneKey.append( OneFilePath ) AllFiles[ statinfo.st_size ] = OneKey else: if statinfo.st_size > MinSize: # print statinfo.st_size AllFiles

Python问题:'Nonetype' object is not iterable

[解析] 这个错误提示一般发生在将None赋给多个值时. [案例] 定义了如下的函数 def test(): if value == 1: a = b = 1 return a,b value = 0 a,b = test() Python问题:'Nonetype' object is not iterable 原文地址:https://www.cnblogs.com/classics/p/11165596.html

python框架Scrapy报错TypeError: 'float' object is not iterable解决

原因是:Twisted版本高了. 解决办法: 只要把Twisted库降级到16.6.0即可: 1 pip3 install Twisted==16.6.0 2 3 注:Twisted16.6.0安装后,会自动卸载高版本的Twisted python框架Scrapy报错TypeError: 'float' object is not iterable解决

Python: TypeError: 'dict' object is not callable

问题:  TypeError: 'dict' object is not callable 原因:  dict()是python的一个内建函数,如果将dict自定义为一个python字典,在之后想调用dict()函数是会报出"TypeError: 'dict' object is not callable"的错误, 解决办法:  >>>del (dict) Python: TypeError: 'dict' object is not callable 原文地址:ht

TypeError: 'NoneType' object has no attribute '__getitem__'

Buildbot版本:(0.8.10) Bug:TypeError: 'NoneType' object has no attribute '__getitem__' 参考页面:http://trac.buildbot.net/ticket/3107?cversion=0&cnum_hist=3 修改文件slaves.py中出错部分的代码为 1 try: 2 max_builds = int(request.args.get('numbuilds', ['10'])[0]) 3 except (

python 报错——Python TypeError: 'module' object is not callable 原因分析

原因分析:Python导入模块的方法有两种: import module 和 from module import 区别是前者所有导入的东西使用时需加上模块名的限定,而后者则不需要 例: >>>import pprint >>>pprint.pprint(people) OR >>>from pprint import * >>>pprint(people) 正确的代码:>>> import Person>&g

'QueryDict' object is not callable 错误解析

我把request内置库和 requests库  给搞混了 requests使用来发送请求的, request 而是用来获取数据的 别看只有一个单词只差,却让我找了大半天 requests.post(***) 发送请求  post必须是小写的 request.POST.get() 是用来获取数据的 这是错误的代码 re_dict = request.POSt(access_token_url,data={ "client_id": '3792702162', "client_