什么是TypeError: 'NoneType'对象是不可迭代的意思?例子:

for row in data:  # Gives TypeError!
    print(row)

当前回答

你用这样的参数调用write_file:

write_file(foo, bar)

但是你没有正确地定义'foo',或者你在你的代码中有一个拼写错误,所以它创建了一个新的空变量并传入它。

其他回答

它意味着data为None,这不是一个可迭代对象。添加or[]*可以防止异常并且不打印任何东西:

for row in data or []:  # no more TypeError!
    print(row)

*归功于先前的一些评论;请注意,引发异常也可能是一种预期的行为和/或数据设置不当的指示。

因为使用for循环的结果只是一个值,而不是一组值

pola.py

@app.route("/search")
def search():
    title='search'
    search_name =  request.form.get('search')
    
    search_item =   User.query.filter_by(id=search_name).first()

    return render_template('search.html', title=title, search_item=search_item  ) 

search.html(错误的)

{% for p in search %}
{{ p }}

search.html(正确)

<td>{{ search_item  }}</td>

我在数据库里对熊猫犯了这个错误。

此错误的解决方案是在集群中安装库 在这里输入图像描述

这意味着data的值为None。

这意味着数据变量传递的是None(类型为NoneType),它的等效值为空。所以它不能像你尝试的那样,作为一个列表是可迭代的。