追加列表,但错误"NoneType"对象没有属性“追加" [英] appending list but error 'NoneType' object has no attribute 'append'

查看:68
本文介绍了追加列表,但错误"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

推荐答案

列表是可变的

更改

last_list=last_list.append(p.last_name)

last_list.append(p.last_name)

将起作用

这篇关于追加列表,但错误"NoneType"对象没有属性“追加"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆