python中的错误-“NoneType”类型的对象没有len()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44187755/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error in python - object of type 'NoneType' has no len()
提问by Alex
I am not sure what is wrong with my python code:
我不确定我的 python 代码有什么问题:
geneid=request.args.get('geneid')
sql=text('select * from INFO where name=:ident')
genes=engine.execute(sql,ident=geneid).fetchone()
params['objs']=genes
if len(genes)==0:
flash('NO RESULTS')
return render_template('info.html', **params)
The error message is: TypeError: object of type 'NoneType' has no len()
错误信息是:TypeError: object of type 'NoneType' has no len()
Any suggestion? I would like to show a flash message when there is no result in my query. I tried also (but did not work):
有什么建议吗?当我的查询没有结果时,我想显示一条 Flash 消息。我也试过(但没有用):
geneid=request.args.get('geneid')
sql=text('select * from INFO where name=:ident')
genes=engine.execute(sql,ident=geneid).fetchone()
params['objs']=genes
if no genes:
flash('NO RESULTS')
return render_template('info.html', **params)