附加列表但错误“NoneType"对象没有属性“附加" [英] appending list but error 'NoneType' object has no attribute 'append'
本文介绍了附加列表但错误“NoneType"对象没有属性“附加"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个脚本,我在其中为每个用户提取值并将其添加到列表中,但我收到'NoneType' 对象没有属性 'append'".我的代码就像
I have a script in which I am extracting value for every user and adding that in a list but I am getting "'NoneType' object has no attribute 'append'". My code is like
last_list=[]
if p.last_name==None or p.last_name=="":
pass
last_list=last_list.append(p.last_name)
print last_list
我想在列表中添加姓氏.如果没有,则不要将其添加到 list 中.请帮忙注意:p 是我用来从我的模块中获取信息的对象,其中包含所有 first_name 、last_name 、 age 等......请建议......提前致谢
I want to add last name in list. If its none then dont add it in list . Please help Note:p is the object that I am using to get info from my module which have all first_name ,last_name , age etc.... Please suggest ....Thanks in advance
推荐答案
list is mutable
list is mutable
改变
last_list=last_list.append(p.last_name)
到
last_list.append(p.last_name)
会起作用
这篇关于附加列表但错误“NoneType"对象没有属性“附加"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文