Python问题——AttributeError: 'NoneType' object has no attribute 'append'
python提示AttributeError: 'NoneType' object has no attribute 'append'
Python问题——AttributeError: 'NoneType' object has no attribute 'append'
f=open("data.csv")
for line in f:
line = line.strip("\n")
ls = line.split(",")
lt=[]
for word in ls:
word=word.strip()
lt=lt.append(word)
print(",".join(lt))
f.close()
把lt= lt.append(word)改为lt.append(word)后问题解决。
原因:append会修改a本身,并且返回None。不能把返回值再赋值给a。